Combining date and time

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Combining date and time

Mahbub Khandoker-2

Hi there,

I had requested a similar problem. Now I just want to know the way to create a new variable join date and time variable. This is what I want your help.

 

Arrival date      Arrival time       Arrival date and Time (new variable)

2008/04/21      20:58               2008/04/21 20:58

2008/12/19      00:08               2008/12/19 00:08

2008/10/13      10:25               2008/10/13 10:25

 

Thanks in advance.

Mahbub

 


Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail
Reply | Threaded
Open this post in threaded view
|

Re: Combining date and time

Richard Ristow
At 07:38 PM 6/14/2009, Mahbub Khandoker wrote:

I want to know the way to create a new variable join date and time variable.

Arrival date    Arrival time   Arrival date and Time (new variable)
2008/04/21      20:58          2008/04/21 20:58
2008/12/19      00:08          2008/12/19 00:08
2008/10/13      10:25          2008/10/13 10:25

COMPUTE ArvlDtTm = ArvlDate + ArvlTime.
FORMATS ArvlDtTm (DATETIME17).

The date-time variable will display as 'dd-mmm-yyyy hh:mm'
rather than as 'yyyy/mm/dd hh:mm'.
===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Combining date and time

Mahbub Khandoker-2
In reply to this post by Mahbub Khandoker-2
Thanks Richard its work fine.
How it's going to work if date and time both in string format (2009-01-03 and1201)?
Thanks,
Mahbub


--- On Mon, 6/15/09, Richard Ristow <[hidden email]> wrote:

From: Richard Ristow <[hidden email]>
Subject: Re: Combining date and time
To: [hidden email]
Received: Monday, June 15, 2009, 1:31 AM

At 07:38 PM 6/14/2009, Mahbub Khandoker wrote:

I want to know the way to create a new variable join date and time variable.

Arrival date    Arrival time   Arrival date and Time (new variable)
2008/04/21      20:58          2008/04/21 20:58
2008/12/19      00:08          2008/12/19 00:08
2008/10/13      10:25          2008/10/13 10:25

COMPUTE ArvlDtTm = ArvlDate + ArvlTime.
FORMATS ArvlDtTm (DATETIME17).

The date-time variable will display as 'dd-mmm-yyyy hh:mm'
rather than as 'yyyy/mm/dd hh:mm'.
===================== 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


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

Reply | Threaded
Open this post in threaded view
|

Re: Combining date and time

Richard Ristow
At 10:34 PM 6/14/2009, Mahbub Khandoker wrote:

Thanks Richard its work fine. How it's going to work if date and time both in string format ('2009-01-03' and '1201')?

Try this. (Like the earlier code, this is untested; and it has plenty of room for mistakes.):

*  Arrival date is straightforward:                     .
COMPUTE ArrivalDate = NUMBER(ArrivalDateString,SDATE10) .
FORMATS ArrivalDate (ADATE10).

*  Arrival time is more work, because you have a non-   .
*  standard format. Here's one of several ways:         .

COMPUTE #Hrs  = NUMBER(SUBSTR(ArrivalTimeString,1,2),F2).
COMPUTE #Mins = NUMBER(SUBSTR(ArrivalTimeString,3,2),F2).

COMPUTE ArrivalTime = TIME.HMS(#Hrs,#Mins).
FORMATS ArrivalTime (TIME5).

*  Combine, as before:                                  .

COMPUTE ArrivalDtTm = ArrivalDate + ArrivalTime.
FORMATS ArvlDtTm (DATETIME17).

===================== 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