LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

checking for valid date

Solved!
Go to solution

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

0 Kudos
Message 1 of 7
(4,957 Views)
Solution
Accepted by topic author dphan128

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.

 

Message 2 of 7
(4,949 Views)

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.

0 Kudos
Message 3 of 7
(4,945 Views)

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 

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 4 of 7
(4,928 Views)

Hi LandBelenky,

By any chance, could you generate the vi in LV 8.5 since I don't have LV 10.0 !

Thanks,

dphan128

0 Kudos
Message 5 of 7
(4,893 Views)

Here is version 8.0

Tim
GHSP
0 Kudos
Message 6 of 7
(4,889 Views)

Thank you Tim,

dphan128

0 Kudos
Message 7 of 7
(4,879 Views)