Reading a string date

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading a string date

Mario Giesel
Hello all,
 
I wonder how to convert a string variable of the following kind into a date format:

2008-11-17 10:49:46          
2008-11-17 11:14:43          
2008-11-17 11:19:34  
...
 
I tried the function DATETIMEw.d but it didn't work.
 
Thanks for any help!
 
Mario

Mario Giesel
Munich, Germany
Reply | Threaded
Open this post in threaded view
|

Re: Reading a string date

Oliver, Richard

Datetime isn’t a function. It’s a format, and unfortunately your date doesn’t fit the rather strict rules for datetime format, nor does the Date/Time Wizard cover your situation. Try something like this:

 

data list list (",") /stringdate (a20).

begin data

2008-11-17 10:49:46          

2008-11-17 11:14:43          

2008-11-17 11:19:34

end data.

compute #i=index(stringdate, " ").

compute #date=number(substr(stringdate, 1, #i-1), sdate10).

compute #hour=number(substr(stringdate, #i+1), time8).

compute datetimevar=#date+#hour.

format datetimevar (datetime20).

list.

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mario Giesel
Sent: Tuesday, February 17, 2009 12:29 PM
To: [hidden email]
Subject: Reading a string date

 

Hello all,

 

I wonder how to convert a string variable of the following kind into a date format:


2008-11-17 10:49:46          
2008-11-17 11:14:43          
2008-11-17 11:19:34  

...

 

I tried the function DATETIMEw.d but it didn't work.

 

Thanks for any help!

 

Mario

 

Reply | Threaded
Open this post in threaded view
|

Re: Reading a string date

Art Kendall
In reply to this post by Mario Giesel
Open a new instance of SPSS.� Copy the syntax below to a syntax file. Click <run>. Click <all>.

data list list/thedate (sdate10)thetime(time8).
begin data
2008-11-17 10:49:46� � � � � � � � �
2008-11-17 11:14:43� � � � � � � � �
2008-11-17 11:19:34
end data.
numeric wholething(datetime20).
compute wholething = thedate+thetime.
list.

Art Kendall
Social Research Consultants


Mario Giesel wrote:
Hello all,
I wonder how to convert a string variable of the following kind into a date format:

2008-11-17 10:49:46� � � � � � � � � �
2008-11-17 11:14:43� � � � � � � � � �
2008-11-17 11:19:34� �
...
I tried the function DATETIMEw.d but it didn't work.
Thanks for any help!
Mario

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

AW: Reading a string date

Mario Giesel
Thanks to Ergul, Oliver, and Art for their contributions!
I used Arts solution which was easiest and worked fine. Now I can deal with similar kinds of date problems in the future.
 
Good luck
Mario


Von: Art Kendall <[hidden email]>
An: Mario Giesel <[hidden email]>
CC: [hidden email]
Gesendet: Dienstag, den 17. Februar 2009, 20:37:14 Uhr
Betreff: Re: Reading a string date

Open a new instance of SPSS.  Copy the syntax below to a syntax file. Click <run>. Click <all>.

data list list/thedate (sdate10)thetime(time8).
begin data
2008-11-17 10:49:46         
2008-11-17 11:14:43         
2008-11-17 11:19:34
end data.
numeric wholething(datetime20).
compute wholething = thedate+thetime.
list.

Art Kendall
Social Research Consultants


Mario Giesel wrote:
Hello all,
 
I wonder how to convert a string variable of the following kind into a date format:

2008-11-17 10:49:46          
2008-11-17 11:14:43          
2008-11-17 11:19:34  
...
 
I tried the function DATETIMEw.d but it didn't work.
 
Thanks for any help!
 
Mario


Mario Giesel
Munich, Germany