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 (July 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 30 Jul 2009 04:07:37 -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: Time Formats
Comments: To: Keval Khichadia <kkhichadia@yahoo.com>
Comments: cc: "Pirritano, Matthew" <MPirritano@ochca.com>
In-Reply-To:  <997384.78995.qm@web110713.mail.gq1.yahoo.com>
Content-Type: text/html; charset="us-ascii"

<html> <body> At 03:38 PM 7/29/2009, Keval Khichadia wrote:<br><br> <blockquote type=cite class=cite cite="">I have a variable start_time that holds the start time of a class. The format is in for example,<br> &nbsp;<br> start_time<br> &nbsp;<br> 1-Jan-1900 09:25:00<br> 1-Jan-1900 14:15:00<br> &nbsp;<br> I used the below syntax:<br> &nbsp;<br> Compute StartTime = XDATE.TIME(START_TIME).<br> formats StartTime (TIME5).<br> &nbsp;<br> and the output gives<br> &nbsp;<br> 9:25<br> 14:15<br> &nbsp;<br> Is there a way I can get it to read like<br> &nbsp;<br> 9:25 A.M.<br> 2:15 P.M</blockquote><br> As you've heard, there's no format under which an SPSS time value will display that way. Here's some code from a while back, that converts a date-time into a <i>string</i> with AM/PM.&nbsp; It was tested when I posted it(*), but I'm not re-testing it now.<br><br> <tt><font size=2>/*&nbsp; ------------&nbsp;&nbsp;&nbsp; Test data&nbsp;&nbsp;&nbsp; ------------&nbsp; */<br> NEW FILE.<br> INPUT PROGRAM.<br> .&nbsp; NUMERIC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIME_VAL (DATETIME22).<br> .&nbsp; VARIABLE WIDTH&nbsp;&nbsp;&nbsp;&nbsp; TIME_VAL (22).<br> .&nbsp; VARIABLE ALIGNMENT TIME_VAL (CENTER).<br><br> .&nbsp; COMPUTE&nbsp; TIME_VAL = $TIME.<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(06,06,1944) + TIME.HMS(10,34,56).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(02,14,1966) + TIME.HMS(15,54,32).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(01,10,2001) + TIME.HMS(13,23,45).<br> .&nbsp; END CASE.<br><br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,03,2002) + TIME.HMS(23,30,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(00,00,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(00,30,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(01,00,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(01,30,00).<br> .&nbsp; END CASE.<br><br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(11,30,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(12,00,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(12,30,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(13,00,00).<br> .&nbsp; END CASE.<br> .&nbsp; COMPUTE&nbsp; TIME_VAL = DATE.MDY(07,04,2002) + TIME.HMS(13,30,00).<br> .&nbsp; END CASE.<br> END FILE.<br> END INPUT PROGRAM.<br> EXECUTE.<br><br> /*&nbsp; ------------ Desired format&nbsp; ------------&nbsp; */<br> /* Target output variable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br> STRING&nbsp; CVT&nbsp;&nbsp;&nbsp;&nbsp; (A22).<br> /* Scratch intermediate variables */<br> STRING&nbsp; #DATE&nbsp;&nbsp; (A10).<br> NUMERIC #TIME&nbsp;&nbsp; (TIME10)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /#ATIME&nbsp; (TIME10).<br> STRING&nbsp; #HMS&nbsp;&nbsp;&nbsp; (A08)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /#AMPM&nbsp;&nbsp; (A02).<br><br> COMPUTE #DATE&nbsp;&nbsp; = STRING(TIME_VAL,ADATE10).<br><br> COMPUTE #TIME&nbsp;&nbsp; = XDATE.TIME(TIME_VAL).<br> DO IF&nbsp;&nbsp;&nbsp; (#TIME &lt; TIME.HMS(01)).<br> .&nbsp; COMPUTE #ATIME = #TIME + TIME.HMS(12).<br> .&nbsp; COMPUTE #HMS&nbsp;&nbsp; = STRING(#ATIME,TIME08).<br> .&nbsp; COMPUTE #AMPM&nbsp; = 'AM'.<br> ELSE IF&nbsp; (#TIME &lt; TIME.HMS(12)).<br> .&nbsp; COMPUTE #ATIME = #TIME.<br> .&nbsp; COMPUTE #HMS&nbsp; = STRING(#ATIME,TIME08).<br> .&nbsp; COMPUTE #AMPM = 'AM'.<br> ELSE IF&nbsp; (#TIME &lt; TIME.HMS(13)).<br> .&nbsp; COMPUTE #ATIME = #TIME.<br> .&nbsp; COMPUTE #HMS&nbsp; = STRING(#ATIME,TIME08).<br> .&nbsp; COMPUTE #AMPM = 'PM'.<br> ELSE.<br> .&nbsp; COMPUTE #ATIME = #TIME - TIME.HMS(12).<br> .&nbsp; COMPUTE #HMS&nbsp;&nbsp; = STRING(#ATIME,TIME08).<br> .&nbsp; COMPUTE #AMPM&nbsp; = 'PM'.<br> END IF.<br><br> COMPUTE CVT = CONCAT(#DATE,' ',#HMS,' ',#AMPM).<br><br> /*&nbsp; ------------&nbsp;&nbsp;&nbsp; Display&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ------------&nbsp; */<br> *&nbsp; Scratch variables as permanent variables, for display .<br> NUMERIC NUM_TM&nbsp; (TIME10)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /NUM_ADJT(TIME10).<br> STRING&nbsp; STR_DT&nbsp; (A10)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /STR_HMS (A08)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (A02).<br> COMPUTE&nbsp;&nbsp;&nbsp; STR_DT&nbsp;&nbsp; = #DATE.<br> COMPUTE&nbsp;&nbsp;&nbsp; NUM_TM&nbsp;&nbsp; = #TIME.<br> COMPUTE&nbsp;&nbsp;&nbsp; NUM_ADJT = #ATIME.<br> COMPUTE&nbsp;&nbsp;&nbsp; STR_HMS&nbsp; = #HMS.<br> COMPUTE&nbsp;&nbsp;&nbsp; AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = #AMPM.<br><br> STRING&nbsp; X (A2).<br> COMPUTE X = '&nbsp; '.<br> EXECUTE.<br> LIST VARIABLES=TIME_VAL X CVT.<br><br> List<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIME_VAL X&nbsp; CVT<br><br> &nbsp; 31-OCT-2003 00:01:26&nbsp;&nbsp;&nbsp; 10/31/2003 12:01:26 AM<br> &nbsp; 06-JUN-1944 10:34:56&nbsp;&nbsp;&nbsp; 06/06/1944 10:34:56 AM<br> &nbsp; 14-FEB-1966 15:54:32&nbsp;&nbsp;&nbsp; 02/14/1966&nbsp; 3:54:32 PM<br> &nbsp; 10-JAN-2001 13:23:45&nbsp;&nbsp;&nbsp; 01/10/2001&nbsp; 1:23:45 PM<br> &nbsp; 03-JUL-2002 23:30:00&nbsp;&nbsp;&nbsp; 07/03/2002 11:30:00 PM<br> &nbsp; 04-JUL-2002 00:00:00&nbsp;&nbsp;&nbsp; 07/04/2002 12:00:00 AM<br> &nbsp; 04-JUL-2002 00:30:00&nbsp;&nbsp;&nbsp; 07/04/2002 12:30:00 AM<br> &nbsp; 04-JUL-2002 01:00:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp; 1:00:00 AM<br> &nbsp; 04-JUL-2002 01:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp; 1:30:00 AM<br> &nbsp; 04-JUL-2002 11:30:00&nbsp;&nbsp;&nbsp; 07/04/2002 11:30:00 AM<br> &nbsp; 04-JUL-2002 12:00:00&nbsp;&nbsp;&nbsp; 07/04/2002 12:00:00 PM<br> &nbsp; 04-JUL-2002 12:30:00&nbsp;&nbsp;&nbsp; 07/04/2002 12:30:00 PM<br> &nbsp; 04-JUL-2002 13:00:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp; 1:00:00 PM<br> &nbsp; 04-JUL-2002 13:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp; 1:30:00 PM<br><br> Number of cases read:&nbsp; 14&nbsp;&nbsp;&nbsp; Number of cases listed:&nbsp; 14<br><br> <br> LIST VARIABLES=TIME_VAL X STR_DT NUM_TM NUM_ADJT STR_HMS AM.<br><br> List<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIME_VAL X&nbsp; STR_DT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUM_TM&nbsp;&nbsp; NUM_ADJT STR_HMS&nbsp; AM<br><br> &nbsp; 31-OCT-2003 00:01:26&nbsp;&nbsp;&nbsp; 10/31/2003&nbsp;&nbsp;&nbsp; 0:01:26&nbsp;&nbsp; 12:01:26 12:01:26 AM<br> &nbsp; 06-JUN-1944 10:34:56&nbsp;&nbsp;&nbsp; 06/06/1944&nbsp;&nbsp; 10:34:56&nbsp;&nbsp; 10:34:56 10:34:56 AM<br> &nbsp; 14-FEB-1966 15:54:32&nbsp;&nbsp;&nbsp; 02/14/1966&nbsp;&nbsp; 15:54:32&nbsp;&nbsp;&nbsp; 3:54:32&nbsp; 3:54:32 PM<br> &nbsp; 10-JAN-2001 13:23:45&nbsp;&nbsp;&nbsp; 01/10/2001&nbsp;&nbsp; 13:23:45&nbsp;&nbsp;&nbsp; 1:23:45&nbsp; 1:23:45 PM<br> &nbsp; 03-JUL-2002 23:30:00&nbsp;&nbsp;&nbsp; 07/03/2002&nbsp;&nbsp; 23:30:00&nbsp;&nbsp; 11:30:00 11:30:00 PM<br> &nbsp; 04-JUL-2002 00:00:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp;&nbsp; 0:00:00&nbsp;&nbsp; 12:00:00 12:00:00 AM<br> &nbsp; 04-JUL-2002 00:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp;&nbsp; 0:30:00&nbsp;&nbsp; 12:30:00 12:30:00 AM<br> &nbsp; 04-JUL-2002 01:00:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp;&nbsp; 1:00:00&nbsp;&nbsp;&nbsp; 1:00:00&nbsp; 1:00:00 AM<br> &nbsp; 04-JUL-2002 01:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp;&nbsp; 1:30:00&nbsp;&nbsp;&nbsp; 1:30:00&nbsp; 1:30:00 AM<br> &nbsp; 04-JUL-2002 11:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp; 11:30:00&nbsp;&nbsp; 11:30:00 11:30:00 AM<br> &nbsp; 04-JUL-2002 12:00:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp; 12:00:00&nbsp;&nbsp; 12:00:00 12:00:00 PM<br> &nbsp; 04-JUL-2002 12:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp; 12:30:00&nbsp;&nbsp; 12:30:00 12:30:00 PM<br> &nbsp; 04-JUL-2002 13:00:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp; 13:00:00&nbsp;&nbsp;&nbsp; 1:00:00&nbsp; 1:00:00 PM<br> &nbsp; 04-JUL-2002 13:30:00&nbsp;&nbsp;&nbsp; 07/04/2002&nbsp;&nbsp; 13:30:00&nbsp;&nbsp;&nbsp; 1:30:00&nbsp; 1:30:00 PM<br><br> Number of cases read:&nbsp; 14&nbsp;&nbsp;&nbsp; Number of cases listed:&nbsp; 14<br> </font></tt>..................................<br> *Posted:<br> Date:&nbsp;&nbsp;&nbsp; Fri, 31 Oct 2003 00:05:42 -0500<br> From:&nbsp;&nbsp;&nbsp; Richard Ristow &lt;wrristow@mindspring.com&gt;<br> Subject: Re: $time AM/PM<br> To:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SPSSX-L@LISTSERV.UGA.EDU<br> </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