LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments:   To: brucercolton@comcast.net
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:&nbsp; 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&nbsp; This variable needs to be datetime17 format.</blockquote><br><br> <tt><font size=2>NUMERIC Date&nbsp;&nbsp;&nbsp; (DATE11)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time&nbsp;&nbsp;&nbsp; (TIME5).<br><br> COMPUTE Date&nbsp;&nbsp;&nbsp; = NUMBER(SUBSTR(StringDt,1,10),SDATE10).<br> COMPUTE Time&nbsp;&nbsp;&nbsp; = NUMBER(SUBSTR(StringDt,11)&nbsp; ,TIME5).<br><br> <br> NUMERIC NumbrDT (DATETIME17).<br> COMPUTE NumbrDT = Date + Time.<br><br> LIST.<br> |-----------------------------|---------------------------|<br> |Output Created&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |26-OCT-2009 22:04:57&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br> |-----------------------------|---------------------------|<br> StringDT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date&nbsp; Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NumbrDT<br><br> 2009-01-06 16:00 06-JAN-2009 16:00 06-JAN-2009 16:00<br><br> Number of cases read:&nbsp; 1&nbsp;&nbsp;&nbsp; Number of cases listed:&nbsp; 1<br> </font></tt>=============================<br> APPENDIX: Test data, and code<br> =============================<br> <tt><font size=2>DATA LIST FIXED/<br> &nbsp; StringDT&nbsp; 01-16 (A).<br> BEGIN DATA<br> 2009-01-06 16:00<br> END DATA.<br><br> NUMERIC Date&nbsp;&nbsp;&nbsp; (DATE11)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time&nbsp;&nbsp;&nbsp; (TIME5).<br><br> COMPUTE Date&nbsp;&nbsp;&nbsp; = NUMBER(SUBSTR(StringDt,1,10),SDATE10).<br> COMPUTE Time&nbsp;&nbsp;&nbsp; = NUMBER(SUBSTR(StringDt,11)&nbsp; ,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


Back to: Top of message | Previous page | Main SPSSX-L page