|
I have a string variable (A16) that gives both date and military time in this format: 2009-01-06 16:00 This is Jan. 6, 2009 hr 16. Using SUBSTR I can pull out day, month and year, and construct 01/06/2009 using CONCAT. This gives a new string variable, call it build_date. Then: COMPUTE newdate=NUMBER(build_date,ADATE10). FORMAT newdate (DATE11). This gives newdate of the form: 06-Jan-2009. So far OK. Now the problem: I need to take newdate (or it's equivalent) together with 16:00 to give me 06-Jan-2007 16:00 This variable needs to be datetime17 format. Newdate is date11, and 16:00 is A5, so how can I bring these 2 together? I welcome any suggestions. Thanks. |
|
Why not build it from the original string variable? Try the Date
and Time Wizard to see what it does. From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Bruce Colton I have a string
variable (A16) that gives both date and military time in this format:
2009-01-06 16:00 This is Jan. 6,
2009 hr 16. Using SUBSTR I can pull out day, month and year, and
construct 01/06/2009 using CONCAT. This gives a new string variable, call
it build_date. Then: COMPUTE
newdate=NUMBER(build_date,ADATE10). FORMAT newdate
(DATE11). This gives
newdate of the form: 06-Jan-2009. So far OK.
Now the problem: I need to take newdate (or it's equivalent) together
with 16:00 to give me 06-Jan-2007
16:00 This variable needs to be datetime17 format. Newdate
is date11, and 16:00 is A5, so how can I bring these 2 together? I welcome
any suggestions. Thanks. |
|
In reply to this post by Bruce Colton
At 08:33 PM 10/26/2009, Bruce Colton wrote:
I have a string variable (A16) that gives both date and military time in this format: 2009-01-06 16:00 NUMERIC Date (DATE11) Time (TIME5). COMPUTE Date = NUMBER(SUBSTR(StringDt,1,10),SDATE10). COMPUTE Time = NUMBER(SUBSTR(StringDt,11) ,TIME5). NUMERIC NumbrDT (DATETIME17). COMPUTE NumbrDT = Date + Time. LIST. |-----------------------------|---------------------------| |Output Created |26-OCT-2009 22:04:57 | |-----------------------------|---------------------------| StringDT Date Time NumbrDT 2009-01-06 16:00 06-JAN-2009 16:00 06-JAN-2009 16:00 Number of cases read: 1 Number of cases listed: 1 ============================= APPENDIX: Test data, and code ============================= DATA LIST FIXED/ StringDT 01-16 (A). BEGIN DATA 2009-01-06 16:00 END DATA. NUMERIC Date (DATE11) Time (TIME5). COMPUTE Date = NUMBER(SUBSTR(StringDt,1,10),SDATE10). COMPUTE Time = NUMBER(SUBSTR(StringDt,11) ,TIME5). NUMERIC NumbrDT (DATETIME17). COMPUTE NumbrDT = Date + Time. LIST. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
| Free forum by Nabble | Edit this page |
