How to? Add 10 years

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,602
46
Albuquerque, NM
prospero.unm.edu
#3
ISO: %@eval[%_year + 10]-%_month-%_day
(or use your own style)
assuming you are not close enough to midnight of the last day of a month so the date might change between retrieving its various parts
But you'll need to check for leap days (today!) If today is a leap day, then ten years from today ain't.
 

samintz

Scott Mintz
May 20, 2008
1,271
11
Solon, OH, USA
#4
Except that 02-29-2022 is not a valid date.

I basically used @makeage to give a magic number that represents 10 years.
Since @makeage[1/1/1601] returns 0, I figured 1/1/1611 would be 10 years.
Code:
So, 10 years from today is:
echo %@agedate[%@eval[%@makeage[%_date] + %@makeage[1/1/1611]]]
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,602
46
Albuquerque, NM
prospero.unm.edu
#5
I basically used @makeage to give a magic number that represents 10 years. Since @makeage[1/1/1601] returns 0, I figured 1/1/1611 would be 10 years.
Code:
So, 10 years from today is:
echo %@agedate[%@eval[%@makeage[%_date] + %@makeage[1/1/1611]]]
So 10 years from May 23, 1970 would be:
Code:
echo %@agedate[%@eval[%@makeage[1970-05-23] + %@makeage[1611-01-01]]]
10 years could be 3652 days, or 3653 days, or even (very rarely) 3651 days.
 

samintz

Scott Mintz
May 20, 2008
1,271
11
Solon, OH, USA
#6
So 10 years from May 23, 1970 would be:
Code:
echo %@agedate[%@eval[%@makeage[1970-05-23] + %@makeage[1611-01-01]]]
10 years could be 3652 days, or 3653 days, or even (very rarely) 3651 days.
I'm creating a digital certificate and I want the expiration date to be 10 years from today. I don't think a day plus or minus will matter much.
 
#7
I think you should simply add 10 years to the "current" date, then add one *day* if the ending date is "29/feb" for a non-leap year (i.e.: simply replacing day and month with 01/mar).

13/11/1970 + 10 years is 13/11/1980.
29/02/2012 + 10 years is 01/03/2012.
 
#8
I'm creating a digital certificate and I want the expiration date to be 10 years from today. I don't think a day plus or minus will matter much.
Just like children born today - when will their birthdays be in non-leap-years? The problem is not the day count; it is specifying a leap day in a non-leap-year.

%@eval[%_year+10][%if[%_month EQ 2 .and. %_day EQ 29,-03-01,-%_month%_day]

will make 10 years the same date if possible; if today is a leapday, makes it March 1st ten years hence. NOT TESTED!
 
#10
10 years could be 3652 days, or 3653 days, or even (very rarely) 3651 days.
When I first read that I did a double-take, and even after thinking about it it took me a while. I guess that 3651 probably isn't worth worrying about since it hasn't happened for over a hundred years and won't for another 80. Obviously for Scott's certificate expiry example then using 3652 days would seem a decent compromise but if you desire an 'accurate' result then the only way to be sure is to use the 'add ten to the year' method and cater for the special case of 29th Feb.

An interesting diversion, thanks folks ;)