From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

check if date exists in LabVIEW

Solved!
Go to solution
A simple question:
 
I cannot use the Time Stamp Control due to some special user interface requirements.
The user is forced to enter date and time information via some sort of a keypad. (no mouse available)
I have a year, month and day field.
 
How can I best check if the entered date is a valid date. (taking everything into account such as leap year, ...)?
 
Checking the time fields is easy.
I know how to check for a valid date in C++ so I could create a DLL but I was wondering if there is also a pure LabVIEW solution.
Thanks for the help!
0 Kudos
Message 1 of 8
(5,532 Views)
Hi noxus,
you can use the Scan from String function. If you get en error, then the date is wrong.

Mike
0 Kudos
Message 2 of 8
(5,512 Views)
Solution
Accepted by noxus
You can form a "date time record" cluster and see if it produces a valid timestamp. It will validate the month (1..12) and year, The day will wrap, so if you enter 2-29-2008 you'll get 2-29-2008, but if you enter 2-29-2007 you'll get 3-1-2007. See if it works for your purpose.
 
 


Message Edited by altenbach on 06-18-2008 10:13 PM
Message 3 of 8
(5,508 Views)

Great ... that should do the trick!

Thanks for the solution - now I don't need the extra DLL.

 

0 Kudos
Message 4 of 8
(5,492 Views)

Sorry to bring up an old thread. The code helped. At least in LV 2009 an input of day 0 shifts the month back to the last day of the previous month. I don't like that behavior so I added an extra check for this.

 

FixDate.png

0 Kudos
Message 5 of 8
(5,143 Views)

Hello,

 

Your solution is not completed.

 

I wanted  to check if a date (YYMMDD) is valid or not . I minds that have more control than check that the day is comprised between 0-31 and month between 0 and 12.  I wanted to advoid for example that the operator introduce a wrong barcode (ex 31 feb 2015 = 150231).

 

Thanks for your helps

 

Marc

0 Kudos
Message 6 of 8
(4,844 Views)
Of course it is complete in reference to the original question. You are now just adding more requirements. 🙂
You can compare the input date with the date obtained from the processed value to see if they are equal.
0 Kudos
Message 7 of 8
(4,814 Views)

that's true and the solution is so evident... Thanks

0 Kudos
Message 8 of 8
(4,781 Views)