Focal Point
How to create a Date out of characters and strings

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7591058331

May 12, 2005, 02:48 PM
<bigpgo>
How to create a Date out of characters and strings
Hello. I'm trying to create a Date from 2 fields: one is YEAR (format A4), and the other is MM (format is I2). How could I create a Date of format YYM? I have an ugly solution, but I'm sure there is something better. Thank you.


COMPUTE myYear/D4 = ATODBL(YEAR, '4', myYear);
COMPUTE dummyDate/YY = '0000';
COMPUTE dummyDate2/YYMD = dummyDate;
COMPUTE myDate/YYMD = DATEADD(dummyDate2, 'Y', myYear);
COMPUTE myDate2/YYMD = DATEADD(myDate, 'M', MM-1);
COMPUTE myDate3/YYM = myDate2;
-* Finally, myDate3 is of the format that I need. Very ugly but it works.. Any suggestions?
May 12, 2005, 03:09 PM
Prarie
DEFINE FILE CAR
DATE1/A4 = '2005';
DATE2/M = '12';
DATE3/A4 = DATE1;
DATE4/A2 = EDIT(DATE2);

DATE5/A6 = DATE3| DATE4;
END
TABLE FILE CAR
PRINT CAR
DATE3 DATE4 DATE5
END
May 12, 2005, 03:23 PM
<bigpgo>
Thanks guys. TexasStingRay - your solution worked and it's compact, I'll go with that one.
May 04, 2007, 05:13 PM
KK
COMPUTE MonDayYearString/A6MDY = MON | DATE | YEAR;
COMPUTE MonDayYearDATE/MDY = MonDayYearString;
COMPUTE MonDayYearDATE1/MDYY = MonDayYearDATE;

I am getting 05/04/07, so when I tried to convert the date to mdyy format, its resulting in 05/04/1907. How can I get the date in 05/04/2007 format.

Thank you.
May 04, 2007, 10:36 PM
susannah
KK,
You might want to investigate the DATECVT function
Your code is taking an alphabetic string and trying to force it into a whats called a 'smartdate' field, You need to understand the difference.
If all you want is an alphabetic character string that is '05/04/2007', then
COMPUTE MonDayYearString/A6MDY = MON | '/' | DATE |'/' |YEAR; will give you '05/04/07' if indded your year field is '07' and not '2007';
but if you want to sort by this field or do arithmetic with it, you can't, you need to convert it to whats called a smart date, with yymd or ymd or mdyy, etc, format




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID