<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Why MySQL&#8217;s (SQL) DATETIME can and should be avoided</title>
	<atom:link href="http://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/feed/" rel="self" type="application/rss+xml" />
	<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/</link>
	<description>Anything I found worthy to write down.</description>
	<lastBuildDate>Thu, 26 Mar 2026 13:15:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: Stanley</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1797</link>
		<dc:creator>Stanley</dc:creator>
		<pubDate>Fri, 06 Sep 2024 07:50:44 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1797</guid>
		<description>Excellent! you saved my time,i was looking for that. thanks</description>
		<content:encoded><![CDATA[<p>Excellent! you saved my time,i was looking for that. thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1500</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Tue, 28 Apr 2020 14:50:46 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1500</guid>
		<description>Our company still stores some dates as unix timestamps in MySQL.  It was convenient in the beginning, and still is, in some ways.  But from a DB perspective, it just sucks doing queries, both in the outut and in the query you have to write.  And now, our db talks to another DB that uses SQL dates everywhere.  So we are constantly converting back and forth.

I would say everything is wrong about this post.  None of the issues that are listed (all real issues) couldn&#039;t be also solved with SQL dates using UTC.  But the biggest issue is that MySQL doesn&#039;t support 64-bit unix timestamps, which means if you need to use a future date after 2038, everything just breaks.

https://bugs.mysql.com/bug.php?id=12654

The author&#039;s assurance that everything will be fixed before 2038 is surely true.  But guess what?  We need to use future dates now, not in 2038.</description>
		<content:encoded><![CDATA[<p>Our company still stores some dates as unix timestamps in MySQL.  It was convenient in the beginning, and still is, in some ways.  But from a DB perspective, it just sucks doing queries, both in the outut and in the query you have to write.  And now, our db talks to another DB that uses SQL dates everywhere.  So we are constantly converting back and forth.</p>
<p>I would say everything is wrong about this post.  None of the issues that are listed (all real issues) couldn&#8217;t be also solved with SQL dates using UTC.  But the biggest issue is that MySQL doesn&#8217;t support 64-bit unix timestamps, which means if you need to use a future date after 2038, everything just breaks.</p>
<p><a href="https://bugs.mysql.com/bug.php?id=12654" rel="nofollow">https://bugs.mysql.com/bug.php?id=12654</a></p>
<p>The author&#8217;s assurance that everything will be fixed before 2038 is surely true.  But guess what?  We need to use future dates now, not in 2038.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shawn</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1484</link>
		<dc:creator>Shawn</dc:creator>
		<pubDate>Sat, 21 Mar 2020 12:54:23 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1484</guid>
		<description>4. Doing querying for date ranges are MUCH easier
5. Reading is much easier when you do direct queries (if you ask why, you haven&#039;t got into real systems, only kiddie play systems)

remember - SET MYSQL TO UTC !</description>
		<content:encoded><![CDATA[<p>4. Doing querying for date ranges are MUCH easier<br />
5. Reading is much easier when you do direct queries (if you ask why, you haven&#8217;t got into real systems, only kiddie play systems)</p>
<p>remember &#8211; SET MYSQL TO UTC !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shawn</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1483</link>
		<dc:creator>Shawn</dc:creator>
		<pubDate>Sat, 21 Mar 2020 11:55:40 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1483</guid>
		<description>Times have changed, and front-end backend, OS has changed.

RULES

1. mysql ALWAYS SET ON UTC
2. Datetime is good -&gt; for obvious reasons once you really work on backend a lot - on update on create default values easy to set.
3. If you don&#039;t know how to set your mysql to UTC, you should learn. Here is a start: https://stackoverflow.com/questions/19023978/should-mysql-have-its-timezone-set-to-utc
(Use google and search for more resources)</description>
		<content:encoded><![CDATA[<p>Times have changed, and front-end backend, OS has changed.</p>
<p>RULES</p>
<p>1. mysql ALWAYS SET ON UTC<br />
2. Datetime is good -&gt; for obvious reasons once you really work on backend a lot &#8211; on update on create default values easy to set.<br />
3. If you don&#8217;t know how to set your mysql to UTC, you should learn. Here is a start: <a href="https://stackoverflow.com/questions/19023978/should-mysql-have-its-timezone-set-to-utc" rel="nofollow">https://stackoverflow.com/questions/19023978/should-mysql-have-its-timezone-set-to-utc</a><br />
(Use google and search for more resources)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Obvious Guy</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1448</link>
		<dc:creator>Obvious Guy</dc:creator>
		<pubDate>Sat, 07 Sep 2019 21:27:21 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1448</guid>
		<description>Always set MySQL (or any server) to use UTC exclusively.  Problem solved.  Simple.

You should never be storing any time data in a local time zone.  Convert it on display if you have to.</description>
		<content:encoded><![CDATA[<p>Always set MySQL (or any server) to use UTC exclusively.  Problem solved.  Simple.</p>
<p>You should never be storing any time data in a local time zone.  Convert it on display if you have to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1423</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Sat, 15 Jun 2019 01:38:30 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1423</guid>
		<description>This is silly stuff from someone with a narrow view of the world. I used to store everything in unix_timestamp() format, until I stopped. The reason is that when I&#039;m using a DB browser like adminer I can&#039;t decode the unix timestamps in my head. If I&#039;m checking a login DB to see when someone logged in last, the unix timestamps are useless to me. Plus sometimes I want to just dump a DB without having to write a program to convert the timestamp. I can grep a date from the command line. There&#039;s a lot of reasons to have a date in a DB that can be read by humans

PHP has strtotime() which converts just about anything to a unix timestamps, so it&#039;s easy to convert or compare different format times.</description>
		<content:encoded><![CDATA[<p>This is silly stuff from someone with a narrow view of the world. I used to store everything in unix_timestamp() format, until I stopped. The reason is that when I&#8217;m using a DB browser like adminer I can&#8217;t decode the unix timestamps in my head. If I&#8217;m checking a login DB to see when someone logged in last, the unix timestamps are useless to me. Plus sometimes I want to just dump a DB without having to write a program to convert the timestamp. I can grep a date from the command line. There&#8217;s a lot of reasons to have a date in a DB that can be read by humans</p>
<p>PHP has strtotime() which converts just about anything to a unix timestamps, so it&#8217;s easy to convert or compare different format times.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Backes</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1271</link>
		<dc:creator>Peter Backes</dc:creator>
		<pubDate>Fri, 23 Jun 2017 11:17:12 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1271</guid>
		<description>Small correction to my message from yesterday, 15:26: The Note with example at in the MySQL documentation is not the right reference. NOW() would never generate &#039;2005-03-27 02:00:00&#039; because the clock jumps from 01:59:59 to 03:00:00. Therefore the duplicate values in this case are not the problem. The problem is that NOW() will twice have the value &#039;2017-10-29 02:00:00&#039;, in CET/CEST. Compare SELECT UNIX_TIMESTAMP(&#039;2017-10-29 01:59:59&#039;)-UNIX_TIMESTAMP(&#039;2017-10-29 02:00:00&#039;); That is, 2017-10-29 02:00:00-03:59:59 CEST will be incorrectly stored as 2017-10-29 02:00:00-03:59:59 CET.

One further improvement to what I said: If you use LPAD(TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),&#039;%H:%i&#039;),6,&#039;+&#039;) when storing the timezone for disambiguation, you can conveniently use it with CONVERT_TZ().</description>
		<content:encoded><![CDATA[<p>Small correction to my message from yesterday, 15:26: The Note with example at in the MySQL documentation is not the right reference. NOW() would never generate &#8217;2005-03-27 02:00:00&#8242; because the clock jumps from 01:59:59 to 03:00:00. Therefore the duplicate values in this case are not the problem. The problem is that NOW() will twice have the value &#8217;2017-10-29 02:00:00&#8242;, in CET/CEST. Compare SELECT UNIX_TIMESTAMP(&#8217;2017-10-29 01:59:59&#8242;)-UNIX_TIMESTAMP(&#8217;2017-10-29 02:00:00&#8242;); That is, 2017-10-29 02:00:00-03:59:59 CEST will be incorrectly stored as 2017-10-29 02:00:00-03:59:59 CET.</p>
<p>One further improvement to what I said: If you use LPAD(TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),&#8217;%H:%i&#8217;),6,&#8217;+') when storing the timezone for disambiguation, you can conveniently use it with CONVERT_TZ().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Backes</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1270</link>
		<dc:creator>Peter Backes</dc:creator>
		<pubDate>Thu, 22 Jun 2017 14:41:05 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1270</guid>
		<description>Addendum: Why not simply use UNIX_TIMESTAMP() instead? That prevents the ambiguities of NOW().

Note also that if one insists on storing a DATETIME NOW(), one can additionally store the current timezone for disambiguation: TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),&#039;%H%i&#039;)</description>
		<content:encoded><![CDATA[<p>Addendum: Why not simply use UNIX_TIMESTAMP() instead? That prevents the ambiguities of NOW().</p>
<p>Note also that if one insists on storing a DATETIME NOW(), one can additionally store the current timezone for disambiguation: TIME_FORMAT(TIMEDIFF(NOW(), UTC_TIMESTAMP),&#8217;%H%i&#8217;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Backes</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1269</link>
		<dc:creator>Peter Backes</dc:creator>
		<pubDate>Thu, 22 Jun 2017 13:26:35 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1269</guid>
		<description>You say &quot;The short and not-so-clever answer is that you could always use MySQL’s UNIX_TIMESTAMP( NOW() ) for this.&quot; Please don&#039;t do this! UNIX_TIMESTAMP(NOW()) still uses NOW(), which means the UNIX timestamp you generate may be wrong. See the Note with example at https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp in the MySQL documentation.</description>
		<content:encoded><![CDATA[<p>You say &#8220;The short and not-so-clever answer is that you could always use MySQL’s UNIX_TIMESTAMP( NOW() ) for this.&#8221; Please don&#8217;t do this! UNIX_TIMESTAMP(NOW()) still uses NOW(), which means the UNIX timestamp you generate may be wrong. See the Note with example at <a href="https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp" rel="nofollow">https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp</a> in the MySQL documentation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kamil Mikolajczyk</title>
		<link>https://billauer.se/blog/2009/03/mysql-datetime-epoch-unix-time/comment-page-2/#comment-1223</link>
		<dc:creator>Kamil Mikolajczyk</dc:creator>
		<pubDate>Mon, 02 Jan 2017 09:56:16 +0000</pubDate>
		<guid isPermaLink="false">https://billauer.se/blog/?p=34#comment-1223</guid>
		<description>I am working on a project where we need to store employee&#039;s working hours. First, we started with timestamps, and the for example: we have an employee in New York (GMT-5), Berlin (GMT+1) and Sydney (GMT+10), they all work from 8am to 4pm

Here are the timestamps of their start of work for today:
Berlin: Mon Jan 02 07:00:00 UTC 2017 1483340400000
New York: Mon Jan 02 13:00:00 UTC 2017 1483362000000
Sydney: Sun Jan 01 22:00:00 UTC 2017 1483308000000

I want to query for all employees who worked today (date-wise)

SELECT * FROM `logged_work` WHERE timestamp_start &gt;= &#039;2017-01-02&#039; 

and with timestamps I am getting only 2 results, mysql treats Sydney&#039;s time as yesterday.

DATETIME columns were only option to solve it</description>
		<content:encoded><![CDATA[<p>I am working on a project where we need to store employee&#8217;s working hours. First, we started with timestamps, and the for example: we have an employee in New York (GMT-5), Berlin (GMT+1) and Sydney (GMT+10), they all work from 8am to 4pm</p>
<p>Here are the timestamps of their start of work for today:<br />
Berlin: Mon Jan 02 07:00:00 UTC 2017 1483340400000<br />
New York: Mon Jan 02 13:00:00 UTC 2017 1483362000000<br />
Sydney: Sun Jan 01 22:00:00 UTC 2017 1483308000000</p>
<p>I want to query for all employees who worked today (date-wise)</p>
<p>SELECT * FROM `logged_work` WHERE timestamp_start &gt;= &#8217;2017-01-02&#8242; </p>
<p>and with timestamps I am getting only 2 results, mysql treats Sydney&#8217;s time as yesterday.</p>
<p>DATETIME columns were only option to solve it</p>
]]></content:encoded>
	</item>
</channel>
</rss>
