I'm trying to get a date that is one year from the date I specify.
My code looks like this:
$futureDate=date('Y-m-d',strtotime('+one year',$startDate));
It's returning the wrong date.... any ideas why?
Thanks!
I'm trying to get a date that is one year from the date I specify.
My code looks like this:
$futureDate=date('Y-m-d',strtotime('+one year',$startDate));
It's returning the wrong date.... any ideas why?
Thanks!
If you are using PHP 5.3, it is because you need to set the default time zone:
date_default_timezone_set()
Try This
$nextyear = date("M d,Y",mktime(0, 0, 0, date("m",strtotime($startDate)), date("d",strtotime($startDate)), date("Y",strtotime($startDate))+1));
strtotime()
is returning bool(false)
, because it can't parse the string '+one year'
(it doesn't understand "one"). false
is then being implicitly cast to the integer
timestamp 0
. It's a good idea to verify strtotime()
's output isn't bool(false)
before you go shoving it in other functions.
Return Values
Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.
Try this
$newEndingDate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($StaringDate)) . " + 365 day"));
or
$newEndingDate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($StaringDate)) . " + 1 year"));