Please help calculate age between dates:
31.August.1993 and 01.March.2019 !
Thank you and best regards
Hi Jure,
Can you please try the below logic,
If ( birth month > current month ) age = ( curr year - ( birth year + 1 ) ) - if birth month = current month and birth day >= currDay age =( curr year - ( birth year + 1 ) ) - otherwise age = ( curr year - birth year )
Michael,
That's a question that cannot be answered precisely. One month prior to 28-Feb-2019 could be 31-Jan-2019 for a house rent that has to be paid at the end of each month. Or it could be 28-Jan-2019 for a car lease payment due date because that's how it was specified in the contract, the obligation to pay the 28th of each month. Trying to add or substract months is not straight forward because each month has a different number of days, so you need to specify how do you want to handle months. Maybe you want to use the average number of days a month has which is 30.44. Some financial applications use 30.5, for example, when quoting a car lease. But when calculating the actual interest they calculate the number of days between the last and next due dates. So, the first thing will be to specify how do you want to express a person's age and how it should be expressed if you want to use months. What I'm trying to say is you are going to need several If...Then statements in your code to reflect the desired rules.
Regards,
Ricardo
Hi All, starting new reply to retrace back to reason for initial reply.
From a computer science perspective I prefer using functions where the reverse function on function's return value returns the original value.
Let us therefore discuss function "add M months; then add D days." Inverse function therefore is "subtract D days; then subtract M months."
When that is my premise I cannot add full months when initial input has day-of-month = 29 or 30 or 31. When an out-of-month day is reduced to end-of-month, I cannot reverse from output to input.
Example (in case of this question): What is "one month prior to 28-Feb-2019?
And THAT is where the root of calendar calculation issues originates?
There are very good reasons for international finance where I currently work to expres everything as number of days instead of years and months.
HTH /Michael
Thanks Michael ,
So my answer is 25 years, 6 months, and 1 day.
Best regard
Jure
Hi Jure, my attempt:
Action | Added | Result |
Initial date | - none - | 31-Aug-1993 |
Add 25 years | 25Y | 31-Aug-2018 |
Add 5 months | 25Y, 5M | 31-Jan-2019 |
Add 28 days | 25Y, 5M, 28D | 28-Feb-2019 |
Add 1 more day | 25Y, 5M, 29D | 01-Mar-2019 |
So my answer is 25 years, 5 months, and 29 days.
HTH /Michael