Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting date to character

Status
Not open for further replies.

nirmalraj

MIS
Apr 20, 2005
33
US
hi,

I have date 08/20/54 in the format MMDDYY8.I want to create a key which is a substring of other variables, for example lastname with the date variable. if I do a substr, all i get is a weird number -1960.

/* key = substr(LAST_NAME,1,3)||substr(DATE,1,2)||substr(DATE,4,2)||substr(DATE,9,2);
*/

Can some one help out with a solution.
Thanks
Nirmal
 
if you want yymmdd you could do something like

substr(Compress(put(<datefield>,YYMMDD10.),'-'),3,6)

remember - the substring of the date is one thing - the subsrting of the formatted date is quite another...

this help?
 
JYMM is correct. The date is stored as the number of days from 1/1/1960 so you will only get the 'weird' number if you use the simple substring function. You need to format the date and then extract the string in JYMM's case using the compress function.
Klaz
 
Thanks jymm.I did something similar to that and it worked out.In fact I had to use compress later.That was helpful.

mm=substr(put(<datefield>,mmddyy8.),1,2);

nirmal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top