View Full Version : how to add 1 year onto date

low tech
12-01-2010, 10:09 AM
Hello everyone

I get a date from a var and I have this to change it into unix date farmat

which is great BUT now I need to add 1 year onto that date so I can set an expiry date and hopefully later I can check against it.

How do I add 1 year onto the date? As in one year from now whenever now is.

Does that make sense.



12-01-2010, 10:16 AM

echo strtotime("+1 day"), "\n";

low tech
12-01-2010, 10:32 AM
Hi djh101

thanks but i'm not clear

this will go to database


but I need to add on 1 year

are you saying I can do this

'".intval(strtotime($date "+365 days"))."'



12-01-2010, 10:35 AM
That depends what you are setting $date as- it has to have a value. I've never used strtotime before, so I'm just going by what I'm reading (feel free to read the link, or read the page on w3schools about strotime), but it seems like all it does is parse a date to unix format? If for $date your are using mktime or date, you can do date("y")+1 or $date = mktime(0, 0, 0, date("m"), date("d"), date("y")+1);

low tech
12-01-2010, 10:52 AM
Thanks djh101

I read / am reading the link

expected date format put into $date
00:31:02 Nov 03 2010 PDT

this '".intval(strtotime($date))."' will convert it to unix 1289049745 format

but I need to add 1 year onto that before I send to DB because I want to set an expiry date that I can check against.

thanks for trying tho, appreciate it.

if anybody can explain how I achieve this that would be great


12-01-2010, 11:34 AM
Actually, with a little reading about UNIX time format and a little testing, '".intval(strtotime($date."+1 year"))."' will return whatever you have in $date plus 1 year (31536000 seconds). If you want to add the expiration manually when you get the string, though, date("y")+1 will still work.

low tech
12-01-2010, 12:09 PM

yeh that looks like it will do the trick --- excellent effort

I was reading this page that I found



thanks very much --- :-)