Login  Register

Re: Date tranformation

Posted by David Marso on Apr 15, 2014; 12:22pm
URL: http://spssx-discussion.165.s1.nabble.com/Date-tranformation-tp5725443p5725446.html

Are you certain that you want to lose the time information?
If you want to retain it:
data list /time_inserted (A20).
BEGIN DATA
2014-2-3 15:28:18
2014-2-3 16:38:4
2013-12-20 17:53:0
2014-1-23 17:24:45
2014-2-10 11:21:32
END DATA.
COMPUTE #space=CHAR.INDEX(time_inserted," ").
COMPUTE DT = NUMBER(CHAR.SUBSTR(time_inserted,1,#space),SDATE10)
           + NUMBER(CHAR.SUBSTR(time_inserted,#space+1),TIME).
FORMATS DT (DATETIME).
LIST.
 
 
time_inserted                          DT
 
2014-2-3 15:28:18    03-FEB-2014 15:28:18
2014-2-3 16:38:4     03-FEB-2014 16:38:04
2013-12-20 17:53:0   20-DEC-2013 17:53:00
2014-1-23 17:24:45   23-JAN-2014 17:24:45
2014-2-10 11:21:32   10-FEB-2014 11:21:32
 
 
Number of cases read:  5    Number of cases listed:  5

mils wrote
Hi everyone,

I have the following 'date' variable:

time_inserted
2014-2-3 15:28:18
2014-2-3 16:38:4
2013-12-20 17:53:0
2014-1-23 17:24:45
2014-2-10 11:21:32

and I'm using the following syntax (Date and Time Wizard...) to recode the variable...

* Date and Time Wizard: DOE.
COMPUTE DOE=number(time_inserted, SDATE10).
VARIABLE LABELS DOE 'time_inserted'.
VARIABLE LEVEL  DOE (SCALE).
FORMATS DOE (SDATE10).
VARIABLE WIDTH  DOE(10).
EXECUTE.
fre DOE.

However, the syntax won't 'read' these two dates
2014-2-3 15:28:18
2014-2-3 16:38:4

They have been recoded as sysmis.

Can someone help me with the syntax?

Thanks in advance!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"