03-28-2013 01:59 PM
You're pretty close. I'd still add a quarter of a day to the number of seconds in a year to account for leap years (if you need to get all leap year calculations exactly right, it will be more work). You need to round up to a whole number of years. And you could add a few extra hours (in seconds) to force it to round up a year on a birthday.
03-28-2013 02:12 PM
I wouldn't try and calculate the number of seconds in a year. Let LabVIEW do that. After the subtraction, I would convert the double back into a Date Time Rec using "Seconds to Date/Time", unbundle the year, and subtract off the 1904 starting year. That'll tell you the age. It'll handle leap years itself. This only causes one issue in that it doesn't recongize if your date is equal to the birthdate, so, add 1 to the current date to fix.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
03-28-2013 02:32 PM
@bsvare wrote:
I wouldn't try and calculate the number of seconds in a year. Let LabVIEW do that. After the subtraction, I would convert the double back into a Date Time Rec using "Seconds to Date/Time", unbundle the year, and subtract off the 1904 starting year. That'll tell you the age. It'll handle leap years itself. This only causes one issue in that it doesn't recongize if your date is equal to the birthdate, so, add 1 to the current date to fix.
That is brilliant. Except you need to wire in a TRUE to the UTC Time input when converting back to the time cluster. This will take care of any time zone offsets. You don't even need to add 1 if the day and month are the same.
03-28-2013 02:35 PM
Running into this...
03-28-2013 03:05 PM
Thanks for your help everyone...I'm sure i'll figure it out
03-28-2013 04:14 PM - edited 03-28-2013 04:16 PM
And now for something that actually works, comparable to the the code I was giving above as pseudocode.
03-28-2013 08:41 PM
Ravens Fan that worked perfect...I didnt need any of the bundles or to convert to seconds. but your set up was great...thanks for your help!!
04-09-2013 04:31 PM
I just wanted to mention another way of doing it that is extremely simple, but doesn't compensate for leap year. Hopefully someone else didn't mention it.
Simply convert your months and years into days by using multiple by constant. Sum your current days, months, and years. Do the same for birth days, months, and years. Subtract birth from current. Use quotient and remainder to calculate back into years.