date format

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

date format

Barkat Ullah
Hello,

I have a couple of date variable with dates entered as string variable both as dd/mm/yyyy and yyyy/mm/dd. Is there a way to convert this into date format as dd/mm/yy?

Thank you for your assistance.

_________________________________________________________________

====================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: date format

Richard Ristow
At 08:03 PM 11/28/2008, Barkat Ullah wrote:

>I have a couple of date variable with dates entered as string
>variable both as dd/mm/yyyy and yyyy/mm/dd. Is there a way to
>convert this into date format as dd/mm/yy?

First (and it often matters), SPSS dates are not *in* a format such
as "dd/mm/yy". They are in an SPSS internal form; they can be
*displayed* in many formats (see Date Formats in the Command Syntax Reference).

Second, "dd/mm/yy" is not an available display format. (Most likely
to avoid confusion with the American format "mm/dd/yy"".) Format
EDATE8 will display dates as "dd.mm.yy". (The components of the date
are separated by periods.)

If the variable is named CharDate, you can convert to an SPSS date
that displays with EDATE8 as follows (untested):

NUMERIC Date (EDATE8).

*  If the date is "dd/mm/yyyy", this should work, .
*  although that isn't obvious the first time you .
*  read the Command Syntax Reference:             .

COMPUTE Date = NUMBER(CharDate,EDATE10).

*  If the date is "yyyy/mm/dd", this should work: .

COMPUTE Date = NUMBER(CharDAte,SDATE10).

If instances of both forms occur in the same variable, you'll need a
little logic to determine which in each instance.

-Best of luck,
  Richard

=====================
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: date format

Albert-Jan Roskam
In reply to this post by Barkat Ullah
Hi,

Untested:

compute date = date.dmy(concat(
number(substr(edvar, 1, 2), n2),
number(substr(edvar, 3, 2), n2),
number(substr(edvar, 5, 4), n2))).
formats date (edate30).

The mdy version can be treated almost identically, but only with the 2nd and the 3rd line swapped.

Cheers!!
Albert-Jan

--- On Sat, 11/29/08, Barkat Ullah <[hidden email]> wrote:

> From: Barkat Ullah <[hidden email]>
> Subject: date format
> To: [hidden email]
> Date: Saturday, November 29, 2008, 2:03 AM
> Hello,
>
> I have a couple of date variable with dates entered as
> string variable both as dd/mm/yyyy and yyyy/mm/dd. Is there
> a way to convert this into date format as dd/mm/yy?
>
> Thank you for your assistance.
>
> _________________________________________________________________
>
> ====================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

=====================
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: date format

Richard Ristow
At 07:02 AM 11/29/2008, Albert-jan Roskam wrote:

>compute date = date.dmy(concat(
>    number(substr(edvar, 1, 2), n2),
>    number(substr(edvar, 3, 2), n2),
>    number(substr(edvar, 5, 4), n2))).
>formats date (edate30).

That probably won't work, since it uses numbers (output of 'number'
functions) as arguments to 'concat'. If you omit the 'concat' and its
associated parentheses, it may well work (I haven't tested).

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