Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do PHP and MySQL unix timestamps diverge on 1983-10-29?
    primarykey
    data
    text
    <p>I've been using PHP's <code>strtotime</code> and MySQL's <code>UNIX_TIMESTAMP</code> functions in my app, to convert dates into timestamps. PHP and MySQL are running on my local machine, and these functions generally return the same result, as I expect them to:</p> <pre><code>$ php &lt;?php echo strtotime("2011-06-02"); ?&gt; 1307001600 mysql&gt; SELECT UNIX_TIMESTAMP("2011-06-02") ts; +------------+ | ts | +------------+ | 1307001600 | +------------+ </code></pre> <p>But, sorta by chance, I happened to notice that when I entered <code>1983-01-01</code> as the date, the results were no longer equal:</p> <pre><code>$ php &lt;?php echo strtotime("1983-01-01"); ?&gt; 410263200 mysql&gt; SELECT UNIX_TIMESTAMP("1983-01-01") ts; +-----------+ | ts | +-----------+ | 410256000 | +-----------+ </code></pre> <p>As you can see, PHP returned 410263200, while MySQL returned 410256000 - a difference of 7200 seconds.</p> <p>This got me curious, and I wanted to know on what date the timestamps were no longer equivalent, so I wrote a little program that starts with today's date (in Y-m-d format), uses PHP's <code>strtotime</code> and MySQL's <code>UNIX_TIMESTAMP</code> and compares the results. It then subtracts 1 day from each value and loops until they're no longer equal. </p> <p>The result:</p> <p><strong>1983-10-29</strong></p> <p>On October 29, 1983, for some reason, <code>strtotime</code> and <code>UNIX_TIMESTAMP</code> return values that differ by 7200 seconds. </p> <p>Any ideas?</p> <p>Thanks for reading.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload