Transform time and date into 1 variable

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

Transform time and date into 1 variable

B. Hemmes
Hello everbody,

I have two variables, 1 with time (hh:mm:ss) and 1 with date (dd-mmm-yy) in it.
I want to merge them into 1 variable (dd-mmm-yyyy hh:mm:ss).
Does anyone know how to do this?

Thanks!

Baukje Hemmes
Reply | Threaded
Open this post in threaded view
|

Re: Transform time and date into 1 variable

Richard Ristow
At 05:10 AM 12/18/2006, B. Hemmes wrote:

>I have two variables, 1 with time (hh:mm:ss) and 1 with date
>(dd-mmm-yy) in it. I want to merge them into 1 variable (dd-mmm-yyyy
>hh:mm:ss).

If the date is an SPSS date variable (I'll say, MY_DATE) and the time
is an SPSS time variable (MY_TIME), the corresponding SPSS date-time
value is just the sum:

MY_DTIME = MY_DATE + MY_TIME.

The, you'll want to give it a date-time format (there's only one, in
SPSS):

FORMATS MY_DTIME (DATETIME20).

That will display as dd-mmm-yyyy hh:mm:ss.
...................
Two extra remarks:
. The above assumes you're familiar with SPSS 'date variables', 'time
variables', and 'date-time variables.' These are *numeric* variables,
discussed in section Universals > Date and Time in the Command Syntax
Reference.
. It also assumes that the values of variable MY_DATE are pure dates;
that is, that their value is the midnight that begins the date. (All
SPSS date variables are actually date-time variables; a 'pure date' is
one that's as I describe.)