| Date: | Mon, 26 Oct 2009 22:07:40 -0400 |
| Reply-To: | Richard Ristow <wrristow@mindspring.com> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Richard Ristow <wrristow@mindspring.com> |
| Subject: | Re: string conversion to datetime |
|
| In-Reply-To: | <69201417.2915181256603639390.JavaMail.root@sz0131a.westche
ster.pa.mail.comcast.net> |
| Content-Type: | text/html; charset="us-ascii" |
|---|
<html>
<body>
At 08:33 PM 10/26/2009, Bruce Colton wrote:<br><br>
<blockquote type=cite class=cite cite="">I have a string variable (A16)
that gives both date and military time in this format: 2009-01-06
16:00<br><br>
I need to take [the date] (or its equivalent) together with 16:00 to give
me <br>
06-Jan-2007 16:00 This variable needs to be datetime17
format.</blockquote><br><br>
<tt><font size=2>NUMERIC Date (DATE11)<br>
Time
(TIME5).<br><br>
COMPUTE Date =
NUMBER(SUBSTR(StringDt,1,10),SDATE10).<br>
COMPUTE Time = NUMBER(SUBSTR(StringDt,11)
,TIME5).<br><br>
<br>
NUMERIC NumbrDT (DATETIME17).<br>
COMPUTE NumbrDT = Date + Time.<br><br>
LIST.<br>
|-----------------------------|---------------------------|<br>
|Output
Created
|26-OCT-2009 22:04:57 |<br>
|-----------------------------|---------------------------|<br>
StringDT
Date
Time
NumbrDT<br><br>
2009-01-06 16:00 06-JAN-2009 16:00 06-JAN-2009 16:00<br><br>
Number of cases read: 1 Number of cases
listed: 1<br>
</font></tt>=============================<br>
APPENDIX: Test data, and code<br>
=============================<br>
<tt><font size=2>DATA LIST FIXED/<br>
StringDT 01-16 (A).<br>
BEGIN DATA<br>
2009-01-06 16:00<br>
END DATA.<br><br>
NUMERIC Date (DATE11)<br>
Time
(TIME5).<br><br>
COMPUTE Date =
NUMBER(SUBSTR(StringDt,1,10),SDATE10).<br>
COMPUTE Time = NUMBER(SUBSTR(StringDt,11)
,TIME5).<br><br>
<br>
NUMERIC NumbrDT (DATETIME17).<br>
COMPUTE NumbrDT = Date + Time.<br><br>
LIST.<br><br>
<br><br>
</font></body>
<br>
</html>
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
|