php - Timestamp one hour short

376

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
44

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.

216

Answer

Solution:

try date_default_timezone_set:

date_default_timezone_set('America/Los_Angeles'); //uses daylight savings
date_default_timezone_set('Etc/GMT-8');           //does not use daylight savings

with the desired timezone. Timezones are at http://php.net/manual/en/timezones.php. Set it before any calls to date(), strtotime(), etc.

People are also looking for solutions to the problem: php - Distribute associative array elements into groups with a maximum sum per group

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.