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: 

I'm having trouble with D4.1 in Labview '09. It says to determine someone's age in years, when given current month,day,and year, and the person's birth month, day and year

Solved!
Go to solution

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.

Message 21 of 28
(1,657 Views)

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.

 

 

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"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

Message 22 of 28
(1,649 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 23 of 28
(1,638 Views)

Thanks for your help everyone...I'm sure i'll figure it out

0 Kudos
Message 25 of 28
(1,619 Views)
Solution
Accepted by topic author jrebes

And now for something that actually works, comparable to the the code I was giving above as pseudocode.

 

Message 26 of 28
(1,608 Views)

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!!

0 Kudos
Message 27 of 28
(1,584 Views)

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.

0 Kudos
Message 28 of 28
(1,504 Views)