I need to add one day to a date using Timestamps. The following code should work but it doesn't :
$date = '2014-10-26';
$date_timestamp = strtotime($date); // Converting the date to timestamp
$new_date_timestamp = $date_timestamp + 24*60*60; // Adding one day
$new_date = date("Y-m-d",$new_date_timestamp); // Formating the new date
It returns $new_date = '2014-10-26' instead of 2014-10-27.
Strangely, it works well for other dates. For example, if $date = '2014-10-28', then it returns $new_date = '2014-10-29', as it should.
I am completely stuck. Any idea to help?
Is the system in England? British Summer Time ended on the 26th at 0100. I think this could account for the discrepancy: during BST, the time is GMT+1. In order to return to GMT, you therefore subtract one hour. 0100 becomes 0000, effectively making 10/26 25 hours long.
Pretty weird, try with this instruction:
$new_date_timestamp = strtotime("+1 day", $date_timestamp);
This can be easily accomplished with strtotime:
$date = '2014-10-26';
$new_date = date("Y-m-d", strtotime("+ 1 day", strtotime($date)));
echo $new_date;