Separating Date from Time

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

Separating Date from Time

Scott Hample
How do I reformat a field that includes both Date and Time? I just need the
date portion of the field.

From
11/12/2006 14:12:30

To
11/12/2006

Thanks!
Scott
Reply | Threaded
Open this post in threaded view
|

Re: Separating Date from Time

Richard Ristow
At 08:50 AM 12/19/2006, Scott Hample wrote:

>How do I reformat a field that includes both Date and Time? I just
>need the date portion of the field.
>
>From: 11/12/2006 14:12:30
>To:   11/12/2006

I'm assuming this is an SPSS date-time variable. (I'm bothered, because
you say the current display is "11/12/2006 14:12:30". The only SPSS
format that displays date and time together is named DATETIME and
displays "dd-mmm-yyyy hh:mm:ss.s", i.e. "12-DEC-2006 14:12:30".)

This isn't just reformatting; it has two parts:
A. Truncate the date-time variable to the date only
B. Assign the result a format that displays only date

For the first, use function XDATE.DATE; for the second, assign the
format using FORMATS.

COMPUTE DateOnly = XDATE.DATE(DateTime) /* Step A. */.
FORMATS DateOnly (ADATE10).             /* Step B. */.

If you assign the format, but don't truncate with XDATE.DATE, your
'dates' will still contain the time, and 'dates' that display the same
may not compare as equal.


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.25/593 - Release Date: 12/19/2006 1:17 PM