php - Timestamp one hour short
I am trying to resolve a time entry bug I've been having. The first timestamp in the string below equates toSunday 11/02/14 00:00
if we add 24 hours to it as shown below, we getMonday 11/03/14 00:00
right? If we add 13 hours to it, as shown below, we should get11/03/14 13:00
, I would think!
Although, not sure why this keeps calculating as11/03/14 12:00
, any ideas as to why this is ?
$start_time = $start_date + ($day * 24 * 60 * 60) + ($hours * 60 * 60) + ($minutes * 60);
Variables Printed out
$start_time = 1414900800 + (1 * 24 * 60 * 60) + (13 * 60 * 60) + (00 * 60) = 1415034000 //converted to readable date: 11-03-2014 12:00
Answer
Solution:
You are getting these results because of the Daylight Savings Time switch between 11/02/2014 and 11/03/2014, you are loosing an hours worth of time based on your time zone selected.
Answer
Solution:
try date_default_timezone_set:
with the desired timezone. Timezones are at http://php.net/manual/en/timezones.php. Set it before any calls to date(), strtotime(), etc.