01-20-2012 04:40 PM
Hi,
I received a date string input in the format of DD-MM-YY. How would I programmatically check for valid date in any given year. For example Feb should have only 28 days (except for leap year), Jan only has 31 days, and so on...
Thanks,
dp
Solved! Go to Solution.
01-20-2012 06:41 PM
this should do it.
It works by converting DD-MM-YYYY to seconds and then converting back to a time stamp. It then compares the original timestamp to the reconverted time stamp. If the two are the same, it's a valid date. If it comes back with a different date, it's not valid.
February 31 will become March 2nd. Although they both have the same seconds value, the month and day values are different, so it knows it's not valid.
Cheers.
01-20-2012 06:53 PM
There is a little trick you need to know to get this to work right:
A time stamp is actually a cluster of several elements: fractional seconds, seconds, minutes, hour, day of month, month, year, day of week, day of year and DST.
This presents a little problem because some of these are related to each other (i.e., the timestamp is over-defined). For example, January 1st is also the first day of the year. So if you put 1 in for month and 1 in for day, it will accept this as January 1st. But if you convert it to seconds and then convert back to timestamp. it will give you Month=1 and Day=1.... but it will also give you Day of Year=1. Therefore, if you compare the full timestamps, it will say they are not equal to each other.
The way to get around this is not to compare the full timestamps, but only selected portions. To do this, you have to unbundle them and then pick out only the parts you wanted.
The version above works correctly. The version here looks simpler... but doesn't work because the timestamp is actually over-defined.
01-21-2012 09:18 AM
A time stamp is actually a cluster of several elements: fractional seconds, seconds, minutes, hour, day of month, month, year, day of week, day of year and DST.
That statement is false, a timestamp can be converted into a cluster of those elements. A timestamp is a 128 bit datatype consisting of two U64's, the first the number of seconds since the epoch, and the second a fractional part of a second.
This is shown in the help section 'how labview stores data in memory'.
Ton
01-24-2012 01:24 PM
Hi LandBelenky,
By any chance, could you generate the vi in LV 8.5 since I don't have LV 10.0 !
Thanks,
dphan128
01-24-2012 01:35 PM
Here is version 8.0
01-24-2012 02:32 PM
Thank you Tim,
dphan128