...

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




'".intval(strtotime($date))."'
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.

thanks

LT

djh101
12-01-2010, 10:16 AM
http://php.net/manual/en/function.strtotime.php

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


'".intval(strtotime($date))."'

but I need to add on 1 year

are you saying I can do this

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

???

LT

djh101
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

anyway
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

LT

djh101
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
Hi

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

I was reading this page that I found

http://php.bigresource.com/Track/php-trF74y5i/

anyway

thanks very much --- :-)

LT



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum