Hi Listers,
I have dates in the format YYYY-MM-DD HH:MM:SS.SSS and I need to find the difference between 2 dates. Unfortunately, the dates are strings, not dates, and I can't find that exact format when I look at the date types available in SPSS. 2 options I see. 1. Anyone know how to convert this variable into a date format. I could then do the date arithmetic. 2. How about chopping off the HH:MM:SS.SSS (I don't need that level of detail), and then I could probably throw it in Excel and do the date arithmetic there. Thanks in advance! Nico -- Nico Peruzzi, Ph.D. |
I receive dates like this 20060331 by various means i convert them to the
ussual 1/1/1900=1 convention. A simple one is extract 1st 4 caharcter as text then 5-6 character then 7-8 and then concatenate 5-6/7-8/1-4 and convert to value dates... A pain I know. I am working with what I call a Miami Vice Type system, more commonly known as a legacy system. >From: Nico Peruzzi <[hidden email]> >Reply-To: Nico Peruzzi <[hidden email]> >To: [hidden email] >Subject: date arithmetic on strange date format >Date: Mon, 9 Oct 2006 14:50:46 -0700 > >Hi Listers, > >I have dates in the format YYYY-MM-DD HH:MM:SS.SSS and I need to find the >difference between 2 dates. > >Unfortunately, the dates are strings, not dates, and I can't find that >exact >format when I look at the date types available in SPSS. > >2 options I see. > >1. Anyone know how to convert this variable into a date format. I could >then do the date arithmetic. >2. How about chopping off the HH:MM:SS.SSS (I don't need that level of >detail), and then I could probably throw it in Excel and do the date >arithmetic there. > >Thanks in advance! Nico > >-- >Nico Peruzzi, Ph.D. |
In reply to this post by Nico Peruzzi
The best strategy is usually to parse the string dates into component
parts and construct date variables using functions (see COMPUTE syntax and more complete documentation in Universals section). I usually nest functions for compact code. Where sDate1 and sDate2 are the input dates in string format: COMPUTE Date1 = DATE.mdy(NUMBER(SUBSTR(sDate1,6,2),F2.0), NUMBER(SUBSTR(sDate1,9,2),F2.0), NUMBER(SUBSTR(sDate1,1,4),F4.0) . COMPUTE Date2 = DATE.mdy(NUMBER(SUBSTR(sDate2,6,2),F2.0), NUMBER(SUBSTR(sDate2,9,2),F2.0), NUMBER(SUBSTR(sDate2,1,4),F4.0) . COMPUTE Days = CTIME.days(Date2-Date1) . FORMATS Date1 Date2 (ADATE10) / Days (F4.0). Dennis Deck, PhD RMC Research Corporation [hidden email] -----Original Message----- From: Nico Peruzzi [mailto:[hidden email]] Sent: Monday, October 09, 2006 2:51 PM Subject: date arithmetic on strange date format Hi Listers, I have dates in the format YYYY-MM-DD HH:MM:SS.SSS and I need to find the difference between 2 dates. Unfortunately, the dates are strings, not dates, and I can't find that exact format when I look at the date types available in SPSS. 2 options I see. 1. Anyone know how to convert this variable into a date format. I could then do the date arithmetic. 2. How about chopping off the HH:MM:SS.SSS (I don't need that level of detail), and then I could probably throw it in Excel and do the date arithmetic there. Thanks in advance! Nico -- Nico Peruzzi, Ph.D. |
Free forum by Nabble | Edit this page |