Well I have to ask this but I need to convert a number field to a date for comparison. Here is an example of a number field which contains the date: 61512. I need to convert this thing to a date but after 2 days I cannot get it done. Your assistance is appreciated.
I mean 61512 as a NUMBER is 6*104+1*103+5*102+1*101+2*100.
But your "number" is REALLY a STRING OF NUMERIC CHARACTERS that represent Month 6, Day 12 and Year 2000+12, or am I all wet, out to lunch and whisslin' in the dark?
Actually, Date/Time values are NUMBERS, but NOT the "number" that you have represented. So you will need to CONVERT your STRING to a Date/Time (numeric) value, using a Date/Time function, like the DateSerial() function, by parsing your STRING into the YEAR, MONTH and DAY components in the appropriate function argument.
Skip,
Just traded in my old subtlety...
for a NUANCE!
I need to say - I really need to sort by date which is why my formula addresses the Year - for now. I will have to do records for 4 years after pulling current year first.
Let me comment, that whoever designed this "date" field in THIS way, mdddyy, was 1) ignorant and 2) ought to be hanged by the thumb until numb!
All you need do is PARSE (you cannot use the Split() function as there is no CHARACTER upon which to parse), parse the Year, Month & Day into the arguments of the DateSerial() function, using the MID() starting with your original attempt...
[tt]
stringvar x := totext({PAYROLLDB_EVENT.TRANDATE},"000000");
dateserial(2000+val(mid(x,5,2),val(mid(x,1,2),val(mid(x,3,2))
[/tt]
Notice that the "number" is converted to a 6-character text string, not 7 characters as in your example.
This also assumes that you ONLY have twenty-FIRST century dates, hence adding 2000 to the year value.
Skip,
Just traded in my old subtlety...
for a NUANCE!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.