Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

March 14th not 86400 seconds long?

Tags:

php

In my web application, I have users input a date in a simple textbox. That input (after being sanitized, of course), is run through strtotime(), and 86399 is added to it, to make that timestamp the end of the day written (11:59:59). This is for due date purposes (so if the date passes, the application raises a flag)

For the days I tested, it worked...

January 5th saved as january 5th, at the end of the day.

March 13th saved as March 13th

March 15th saved as March 15th

March 14th, for whatever reason, saved itself as March 15th.

Is March 14th mysteriously a couple seconds short or something??


Update: Thanks to oezi for the solution - worked like a charm. Code as requested:

Old code:

if ($_POST['dateto'] != '') {
    $dateto = strtotime(mysql_real_escape_string($_POST['dateto'])) + 86399;
}

New code:

# Offset to "end of day"
list($y,$m,$d) = explode('-',date("Y-m-d",strtotime($_POST['dateto'])));
$d++;
$dateto = strtotime($y . '-' . $m . '-' . $d) - 1;
like image 911
Julian H. Lam Avatar asked Mar 09 '10 18:03

Julian H. Lam


People also ask

How many seconds is a day in UTC?

Nearly all UTC days contain exactly 86,400 SI seconds with exactly 60 seconds in each minute. UTC is within about one second of mean solar time at 0° longitude, so that, because the mean solar day is slightly longer than 86,400 SI seconds, occasionally the last minute of a UTC day is adjusted to have 61 seconds.


2 Answers

March 14, 2010 is the day Daylight Saving Time begins in the United States. So if you're doing math in the local time zone, March 14 is only 23 hours long.

like image 101
Daniel Pryden Avatar answered Oct 15 '22 21:10

Daniel Pryden


I would assume because this is the beginning of daylight savings time

like image 35
rerun Avatar answered Oct 15 '22 23:10

rerun