Question:
How do I convert a timestamp variable listed as "2006-03-08 08:30:45" into separate columns like Year, Month, Day, Respdate, Time (hhmmss). Thanks, Juan |
Hi Juan
Take a look at this section of Raynald Levesque's web page: http://www.spsstools.net/SampleSyntax.htm#DatesAndTimes You might find a solution there JN> How do I convert a timestamp variable listed as JN> "2006-03-08 08:30:45" into separate columns like Year, JN> Month, Day, Respdate, Time (hhmmss). -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician |
In reply to this post by Juan Navarrete
Hi Juan
JN> How do I convert a timestamp variable listed as JN> "2006-03-08 08:30:45" into separate columns like Year, JN> Month, Day, Respdate, Time (hhmmss). A full answer to your question: DATA LIST LIST/date1 (A19). BEGIN DATA "2006-03-08 08:30:45" END DATA. * Split in components *. COMPUTE yr=NUMBER(SUBSTR(date1,1,4),f4). COMPUTE mo=NUMBER(SUBSTR(date1,6,2),f4). COMPUTE da=NUMBER(SUBSTR(date1,9,2),f4). COMPUTE hour=NUMBER(SUBSTR(date1,12,2),f4). COMPUTE min=NUMBER(SUBSTR(date1,15,2),f4). COMPUTE sec=NUMBER(SUBSTR(date1,18,2),f4). * To combine them into full date and hour *. COMPUTE date2=DATE.DMY(da,mo,yr). COMPUTE htime = TIME.HMS(hour,min,sec) . * Formatting variables *. FORMAT yr TO sec (F4) date2(ADATE10) htime(TIME8). LIST . -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
In reply to this post by Juan Navarrete
Marta , I very impressed about your contribution to this LIST.
Regards. Edward -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Marta García-Granero Sent: Tuesday, August 15, 2006 12:54 PM To: [hidden email] Subject: Re: Timestamp Conversion Hi Juan JN> How do I convert a timestamp variable listed as JN> "2006-03-08 08:30:45" into separate columns like Year, JN> Month, Day, Respdate, Time (hhmmss). A full answer to your question: DATA LIST LIST/date1 (A19). BEGIN DATA "2006-03-08 08:30:45" END DATA. * Split in components *. COMPUTE yr=NUMBER(SUBSTR(date1,1,4),f4). COMPUTE mo=NUMBER(SUBSTR(date1,6,2),f4). COMPUTE da=NUMBER(SUBSTR(date1,9,2),f4). COMPUTE hour=NUMBER(SUBSTR(date1,12,2),f4). COMPUTE min=NUMBER(SUBSTR(date1,15,2),f4). COMPUTE sec=NUMBER(SUBSTR(date1,18,2),f4). * To combine them into full date and hour *. COMPUTE date2=DATE.DMY(da,mo,yr). COMPUTE htime = TIME.HMS(hour,min,sec) . * Formatting variables *. FORMAT yr TO sec (F4) date2(ADATE10) htime(TIME8). LIST . -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
In reply to this post by Juan Navarrete
If you are using SPSS version 13 or later.
First you should change the prsentation of your date from yyyy-mmm-dd hh:mm:ss to something that is available in SPSS such as dd-mmm-yyyy hh:mm:ss or mmm-dd-yyyy hh:mm:ss Then use the date/time wizard available under COMPUTE and extract part of the date. The variable you are extracting part of the date from should be of a "date" type. You will need to do it as many as the number of variable you want to create. That means the first extraction might just be the day, another one will be to create the month. You can't extract 2 variables in one time. I hope this is going to work. Juan Navarrete <[hidden email]> wrote: Question: How do I convert a timestamp variable listed as "2006-03-08 08:30:45" into separate columns like Year, Month, Day, Respdate, Time (hhmmss). Thanks, Juan Nadine Nana, MS Research Data Manager Atlanta GA 404 805 6209 --------------------------------- Want to be your own boss? Learn how on Yahoo! Small Business. |
Free forum by Nabble | Edit this page |