Date conversion

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

Date conversion

Robert L

This will be the first posting where I have no question, but rather an attempt to point at new discoveries which might be handy for others. One of the most common tasks I get is re-formatting date variables since people tend to store dates in so many ways. I have usually used combinations of the CHAR.SUBSTR and DATE.DMY functions, but there seems to be more straightforward ways using the NUMBER function. Some examples:

 

DATA LIST LIST/date1(A10) date2(A11).

BEGIN DATA

2.12.78     2017-12-24

23.7.89     17/6/2

24.11.09    17/7/8

5.7.82        7.8.9

7/8/7          9/12/31

1-1-2017     2017-01-01

31122009     20070807

END DATA.

DATASET NAME date_conv.

 

COMPUTE date1_n=NUMBER(date1,EDATE10).

 

COMPUTE date2_n=NUMBER(date2,SDATE10).

 

FORMATS date1_n date2_n(DATE11).

 

EXECUTE.

 

I have used the European formats here, but it could just as well be the American variants. Neat, isn’t it? I especially like the last example with dates without delimiters, a possibility which came with version 24. Hope this was not trivial…

 

Robert

===================== 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
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Art Kendall
Of course one almost always wants to preserve the original input.
I was wondering why you did not just copy the variables and then use ALTER TYPE.
BUT this snippet of syntax shows why.   ALTER TYPE is not as powerful as NUMBER.
DATA LIST LIST/date1(A10) date2(A11).
BEGIN DATA
2.12.78     2017-12-24
23.7.89     17/6/2
24.11.09    17/7/8
5.7.82        7.8.9
7/8/7          9/12/31
1-1-2017     2017-01-01
31122009     20070807

END DATA.

DATASET NAME date_conv.
COMPUTE date1_n=NUMBER(date1,EDATE10).
COMPUTE date2_n=NUMBER(date2,SDATE10).
FORMATS date1_n date2_n(DATE11).
list.
string mydate1 mydate2 (a11).
compute mydate1 = date1.
compute mydate2 = date2.
list.
ALTER TYPE mydate1 mydate2(Date11).
list.

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

David Marso
Administrator
In reply to this post by Robert L
I believe it would be rather demented to have multiple dates splattered about multiple formats.
BTW your last exemplar doesn't parse at all.

Robert L wrote
This will be the first posting where I have no question, but rather an attempt to point at new discoveries which might be handy for others. One of the most common tasks I get is re-formatting date variables since people tend to store dates in so many ways. I have usually used combinations of the CHAR.SUBSTR and DATE.DMY functions, but there seems to be more straightforward ways using the NUMBER function. Some examples:

DATA LIST LIST/date1(A10) date2(A11).
BEGIN DATA
2.12.78     2017-12-24
23.7.89     17/6/2
24.11.09    17/7/8
5.7.82        7.8.9
7/8/7          9/12/31
1-1-2017     2017-01-01
31122009     20070807
END DATA.
DATASET NAME date_conv.

COMPUTE date1_n=NUMBER(date1,EDATE10).

COMPUTE date2_n=NUMBER(date2,SDATE10).

FORMATS date1_n date2_n(DATE11).

EXECUTE.

I have used the European formats here, but it could just as well be the American variants. Neat, isn’t it? I especially like the last example with dates without delimiters, a possibility which came with version 24. Hope this was not trivial…

Robert

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Robert L
In reply to this post by Robert L
You are naturally right about having multiple formats, they were only meant as examples. The last date works fine here, so why doesn't it at your end?

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För David Marso
Skickat: den 7 juni 2017 15:37
Till: [hidden email]
Ämne: Re: Date conversion

I believe it would be rather demented to have multiple dates splattered about multiple formats.
BTW your last exemplar doesn't parse at all.


Robert L wrote

> This will be the first posting where I have no question, but rather an
> attempt to point at new discoveries which might be handy for others.
> One of the most common tasks I get is re-formatting date variables
> since people tend to store dates in so many ways. I have usually used
> combinations of the CHAR.SUBSTR and DATE.DMY functions, but there
> seems to be more straightforward ways using the NUMBER function. Some examples:
>
> DATA LIST LIST/date1(A10) date2(A11).
> BEGIN DATA
> 2.12.78     2017-12-24
> 23.7.89     17/6/2
> 24.11.09    17/7/8
> 5.7.82        7.8.9
> 7/8/7          9/12/31
> 1-1-2017     2017-01-01
> 31122009     20070807
> END DATA.
> DATASET NAME date_conv.
>
> COMPUTE date1_n=NUMBER(date1,EDATE10).
>
> COMPUTE date2_n=NUMBER(date2,SDATE10).
>
> FORMATS date1_n date2_n(DATE11).
>
> EXECUTE.
>
> I have used the European formats here, but it could just as well be
> the American variants. Neat, isn’t it? I especially like the last
> example with dates without delimiters, a possibility which came with
> version 24. Hope this was not trivial…
>
> Robert
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Date-conversion-tp5734333p5734338.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

David Marso
Administrator
In reply to this post by David Marso
 
date1      date2           date1_n     date2_n
 
2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017
 
>Warning # 1151
>A field to be read under the EDATE format is invalid.  The field must contain
>day, month, and year separated by spaces, dashes, slashes, decimal points, or
>commas.  Note that American style dates (month/day/year) can be read under the
>ADATE format.
>Command line: 349  Current case: 7  Current splitfile group: 1
>Field contents: '31122009'
 
>Warning # 1152
>A field to be read under the SDATE format is invalid.  The field must contain
>year, month, and day separated by spaces, dashes, slashes, decimal points, or
>commas.  The result has been set to the system-missing value.
>Command line: 350  Current case: 7  Current splitfile group: 1
>Field contents: '20070807'
31122009   20070807              .           .
 
 
Number of cases read:  7    Number of cases listed:  7

second LIST.  see sysmis on the last record?
 
date1      date2           date1_n     date2_n
 
2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017
31122009   20070807              .           .
 
 
Number of cases read:  7    Number of cases listed:  7

OTOH:  If you parse the little punk with delimiters as follows you achieve a successful conversion.

DATA LIST LIST/date1(A10) date2(A11).
BEGIN DATA
2.12.78   2017-12-24
23.7.89   17/6/2
24.11.09  17/7/8
5.7.82    7.8.9
7/8/7     9/12/31
1-1-2017  2017-01-01
31122009  20070807
END DATA.
LIST.

DATASET NAME date_conv.
IF INDEX(date1,"./-",1) EQ 0
    date1=CONCAT(CHAR.SUBSTR(date1,1,2),"/",CHAR.SUBSTR(date1,3,2),"/",CHAR.SUBSTR(date1,4)).
IF INDEX(date2,"./-",1) EQ 0
    date2=CONCAT(CHAR.SUBSTR(date2,1,4),"/",CHAR.SUBSTR(date2,5,2),"/",CHAR.SUBSTR(date2,7)).


COMPUTE date1_n=NUMBER(date1,EDATE10).
COMPUTE date2_n=NUMBER(date2,SDATE10).


FORMATS date1_n date2_n(DATE11).
LIST.


Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Art Kendall
In reply to this post by Art Kendall
this is the output on my system. The the last example from the OP appears to work.

Sorry did not see how to get fixed pitch in nabble.


date1      date2           date1_n     date2_n     mydate1     mydate2

2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017 02-DEC-1978           .
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017 23-JUL-1989 17-JUN-2002
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017 24-NOV-2009 17-JUL-2008
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007 05-JUL-1982 07-AUG-2009
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009 07-AUG-2007 09-DEC-2031
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017 01-JAN-2017           .
31122009   20070807    31-DEC-2009 07-AUG-2007 31-DEC-2009           .
                                 .           .           .           .


Number of cases read:  8    Number of cases listed:  8
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

David Marso
Administrator
I'm using version ver 22 if that makes any difference.
It seems to really want those delimiters.

FWIW:  I don't think Nabble gives much formatting options.
Aside from silly animated crap
and the ability to bold stuff it is pretty format illiterate

--
Art Kendall wrote
this is the output on my system. The the last example from the OP appears to work.

Sorry did not see how to get fixed pitch in nabble.


date1      date2           date1_n     date2_n     mydate1     mydate2

2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017 02-DEC-1978           .
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017 23-JUL-1989 17-JUN-2002
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017 24-NOV-2009 17-JUL-2008
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007 05-JUL-1982 07-AUG-2009
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009 07-AUG-2007 09-DEC-2031
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017 01-JAN-2017           .
31122009   20070807    31-DEC-2009 07-AUG-2007 31-DEC-2009           .
                                 .           .           .           .


Number of cases read:  8    Number of cases listed:  8
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Art Kendall
IIRC it wasn't until version 24 that SPSS used minus sign as element separator in  dates except when the month was alpha.

IIRC Sortable date (20170607) is also fairly new
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

David Marso
Administrator
SDATE format has been around for at least twenty years.

On Wed, Jun 7, 2017 at 12:25 PM, Art Kendall [via SPSSX Discussion] <[hidden email]> wrote:
IIRC it wasn't until version 24 that SPSS used minus sign as element separator in  dates except when the month was alpha.

IIRC Sortable date (20170607) is also fairly new
Art Kendall
Social Research Consultants



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Date-conversion-tp5734333p5734345.html
To unsubscribe from Date conversion, click here.
NAML

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Bruce Weaver
Administrator
In reply to this post by David Marso
The raw text tags in Nabble generate fixed font text.  But as we discovered a while ago, they also made the text invisible in the UGA archive for the list.  

http://spssx-discussion.1045642.n5.nabble.com/OT-quot-raw-text-quot-tags-in-Nabble-are-making-text-disappear-in-the-UGA-archive-td5729959.html

Time for another experiment to see if that still happens?  I'll type a statistical limerick twice, once without and once with raw text tags.  Someone who can still see the UGA archive will have to tell us whether it's visible with the tags.

1. Without tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

2. With tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

David Marso wrote
I'm using version ver 22 if that makes any difference.
It seems to really want those delimiters.

FWIW:  I don't think Nabble gives much formatting options.
Aside from silly animated crap
and the ability to bold stuff it is pretty format illiterate

--
Art Kendall wrote
this is the output on my system. The the last example from the OP appears to work.

Sorry did not see how to get fixed pitch in nabble.


date1      date2           date1_n     date2_n     mydate1     mydate2

2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017 02-DEC-1978           .
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017 23-JUL-1989 17-JUN-2002
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017 24-NOV-2009 17-JUL-2008
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007 05-JUL-1982 07-AUG-2009
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009 07-AUG-2007 09-DEC-2031
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017 01-JAN-2017           .
31122009   20070807    31-DEC-2009 07-AUG-2007 31-DEC-2009           .
                                 .           .           .           .


Number of cases read:  8    Number of cases listed:  8
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

David Marso
Administrator
Being as I practically live there these days getting rid of all the bloody SPAM coming through,
I just tuned into planet UGA and this is the result:  Tags don't flow well to UGA.

-----
Time for another experiment to see if that still happens?  I'll type a
statistical limerick twice, once without and once with raw text tags.
Someone who can still see the UGA archive will have to tell us whether it's
visible with the tags.

1. Without tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

2. With tags:
**************************

**************************

Can you believe since May 11 there have been over 2800 instances of slimy spam attempting to assault our sanctum?  The number might be half because a lot of the crap comes in duplicate for some reason. 
BTW: I almost got my girlfriend to dump it on you when I was hospitalized. 
Dodged that bullet my friend. 
All this to get the bloody Post New Topic Button back.


On Wed, Jun 7, 2017 at 2:04 PM, Bruce Weaver [via SPSSX Discussion] <[hidden email]> wrote:
The raw text tags in Nabble generate fixed font text.  But as we discovered a while ago, they also made the text invisible in the UGA archive for the list.  

http://spssx-discussion.1045642.n5.nabble.com/OT-quot-raw-text-quot-tags-in-Nabble-are-making-text-disappear-in-the-UGA-archive-td5729959.html

Time for another experiment to see if that still happens?  I'll type a statistical limerick twice, once without and once with raw text tags.  Someone who can still see the UGA archive will have to tell us whether it's visible with the tags.

1. Without tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

2. With tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

David Marso wrote
I'm using version ver 22 if that makes any difference.
It seems to really want those delimiters.

FWIW:  I don't think Nabble gives much formatting options.
Aside from silly animated crap
and the ability to bold stuff it is pretty format illiterate

--
Art Kendall wrote
this is the output on my system. The the last example from the OP appears to work.

Sorry did not see how to get fixed pitch in nabble.


date1      date2           date1_n     date2_n     mydate1     mydate2

2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017 02-DEC-1978           .
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017 23-JUL-1989 17-JUN-2002
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017 24-NOV-2009 17-JUL-2008
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007 05-JUL-1982 07-AUG-2009
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009 07-AUG-2007 09-DEC-2031
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017 01-JAN-2017           .
31122009   20070807    31-DEC-2009 07-AUG-2007 31-DEC-2009           .
                                 .           .           .           .


Number of cases read:  8    Number of cases listed:  8
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Date-conversion-tp5734333p5734353.html
To unsubscribe from Date conversion, click here.
NAML

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Rich Ulrich

I am reading from UGA, not from Nabble. 

To your question:  There is no verse visible in the  "between tags" section.


--

Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of David Marso <[hidden email]>
Sent: Wednesday, June 7, 2017 2:22:11 PM
To: [hidden email]
Subject: Re: Date conversion
 
Being as I practically live there these days getting rid of all the bloody SPAM coming through,
I just tuned into planet UGA and this is the result:  Tags don't flow well to UGA.

-----
Time for another experiment to see if that still happens?  I'll type a
statistical limerick twice, once without and once with raw text tags.
Someone who can still see the UGA archive will have to tell us whether it's
visible with the tags.

1. Without tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

2. With tags:
**************************

**************************

Can you believe since May 11 there have been over 2800 instances of slimy spam attempting to assault our sanctum?  The number might be half because a lot of the crap comes in duplicate for some reason. 
BTW: I almost got my girlfriend to dump it on you when I was hospitalized. 
Dodged that bullet my friend. 
All this to get the bloody Post New Topic Button back.


On Wed, Jun 7, 2017 at 2:04 PM, Bruce Weaver [via SPSSX Discussion] <[hidden email]> wrote:
The raw text tags in Nabble generate fixed font text.  But as we discovered a while ago, they also made the text invisible in the UGA archive for the list.  

http://spssx-discussion.1045642.n5.nabble.com/OT-quot-raw-text-quot-tags-in-Nabble-are-making-text-disappear-in-the-UGA-archive-td5729959.html

Time for another experiment to see if that still happens?  I'll type a statistical limerick twice, once without and once with raw text tags.  Someone who can still see the UGA archive will have to tell us whether it's visible with the tags.

1. Without tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

2. With tags:
**************************
There once was a vicar at Kew
Who kept his pet cat in a pew.
He taught it to speak
alphabetical Greek,
but it never got farther than mu.
**************************

David Marso wrote
I'm using version ver 22 if that makes any difference.
It seems to really want those delimiters.

FWIW:  I don't think Nabble gives much formatting options.
Aside from silly animated crap
and the ability to bold stuff it is pretty format illiterate

--
Art Kendall wrote
this is the output on my system. The the last example from the OP appears to work.

Sorry did not see how to get fixed pitch in nabble.


date1      date2           date1_n     date2_n     mydate1     mydate2

2.12.78    2017-12-24  02-DEC-1978 24-DEC-2017 02-DEC-1978           .
23.7.89    17/6/2      23-JUL-1989 02-JUN-2017 23-JUL-1989 17-JUN-2002
24.11.09   17/7/8      24-NOV-2009 08-JUL-2017 24-NOV-2009 17-JUL-2008
5.7.82     7.8.9       05-JUL-1982 09-AUG-2007 05-JUL-1982 07-AUG-2009
7/8/7      9/12/31     07-AUG-2007 31-DEC-2009 07-AUG-2007 09-DEC-2031
1-1-2017   2017-01-01  01-JAN-2017 01-JAN-2017 01-JAN-2017           .
31122009   20070807    31-DEC-2009 07-AUG-2007 31-DEC-2009           .
                                 .           .           .           .


Number of cases read:  8    Number of cases listed:  8
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Date-conversion-tp5734333p5734353.html
To unsubscribe from Date conversion, click here.
NAML

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"


View this message in context: Re: Date conversion
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
===================== 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 conversion

Jon Peck
In reply to this post by Robert L
V24 added two new date features.  First, as Robert noted, the delimiter is now optional for
DATEADATEEDATESDATE, and TIME input formats.

Second, YMDHMSw and YMDHMSw.d formats were added for specs like yyyy-mm-dd hh:mm.  The time portion is optional.  This is the ISO 8601 standard.  It is often used for for weblogs and similar things.

See the CSR for details.  With new formats, backward compatibility of the SAV file is a challenge.  The CSR does not mention what happens if you open a sav file with the new format in V23 or earlier, but this new format was engineered so that older versions will interpret it correctly but produce a slightly different but correct display.



On Fri, Jun 2, 2017 at 2:44 AM, Robert Lundqvist <[hidden email]> wrote:

This will be the first posting where I have no question, but rather an attempt to point at new discoveries which might be handy for others. One of the most common tasks I get is re-formatting date variables since people tend to store dates in so many ways. I have usually used combinations of the CHAR.SUBSTR and DATE.DMY functions, but there seems to be more straightforward ways using the NUMBER function. Some examples:

 

DATA LIST LIST/date1(A10) date2(A11).

BEGIN DATA

2.12.78     2017-12-24

23.7.89     17/6/2

24.11.09    17/7/8

5.7.82        7.8.9

7/8/7          9/12/31

1-1-2017     2017-01-01

31122009     20070807

END DATA.

DATASET NAME date_conv.

 

COMPUTE date1_n=NUMBER(date1,EDATE10).

 

COMPUTE date2_n=NUMBER(date2,SDATE10).

 

FORMATS date1_n date2_n(DATE11).

 

EXECUTE.

 

I have used the European formats here, but it could just as well be the American variants. Neat, isn’t it? I especially like the last example with dates without delimiters, a possibility which came with version 24. Hope this was not trivial…

 

Robert

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



--
Jon K Peck
[hidden email]

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

Art Kendall
Do I read your post that my memory was correct that straight sdate (20170608) being acceptable is new to v 24. But sdate with delimiters has been around? e.g., 2017/06/08
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Robert L
In reply to this post by Robert L
Yes, dates without delimiters seem to be new to v24 as you write. But it holds for other formats as well such as ADATE:

DATA LIST LIST /date1(A8).
BEGIN DATA
12312016
END DATA.
DATASET NAME dates.

COMPUTE date2=NUMBER(date1,ADATE8).

EXECUTE.

FORMATS date2(ADATE8).

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Art Kendall
Skickat: den 8 juni 2017 14:08
Till: [hidden email]
Ämne: Re: Date conversion

Do I read your post that my memory was correct that straight sdate (20170608) being acceptable is new to v 24. But sdate with delimiters has been around?
e.g., 2017/06/08



-----
Art Kendall
Social Research Consultants
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Date-conversion-tp5734333p5734369.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Date conversion

Jon Peck
In reply to this post by Art Kendall
SDATE is not new but required delimiters until V24.

For version 24 and higher, delimiters can be omitted in input values for DATE, ADATE, EDATE, and SDATE.
For example, with the ADATE format, the form 10281990 is acceptable. When delimiters are omitted,
single digit specifications for month and day are not supported and year specifications must be 2 or 4
digits. Also, when month names are used, they must be specified in the three letter format when
delimiters are omitted, as in 28OCT1990.


JDATE, however, never allowed delimiters.

On Thu, Jun 8, 2017 at 6:07 AM, Art Kendall <[hidden email]> wrote:
Do I read your post that my memory was correct that straight sdate (20170608)
being acceptable is new to v 24. But sdate with delimiters has been around?
e.g., 2017/06/08



-----
Art Kendall
Social Research Consultants
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Date-conversion-tp5734333p5734369.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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



--
Jon K Peck
[hidden email]

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