<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Preacher &#187; timestamp</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/tag/timestamp/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>A MySQL blog, from a MySQL DBA</description>
	<lastBuildDate>Wed, 16 Jun 2010 13:13:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Once upon a timestamp(milliseconds)&#8230;.</title>
		<link>http://mysqlpreacher.com/wordpress/2009/08/once-upon-a-timestampmilliseconds/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/08/once-upon-a-timestampmilliseconds/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 12:53:49 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[microsecond]]></category>
		<category><![CDATA[millisecond]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=234</guid>
		<description><![CDATA[Once upon a time`stamp`, in a `data`base far far away, someone filed a bug named: `Microseconds precision is not retained by TIME, DATETIME, and TIMESTAMP field types.` - Bug Number 8523. This was the beginning of 2005, yet now that we are approaching the end of 2009, after 4.5 years, many (including myself) are still asking for this.]]></description>
			<content:encoded><![CDATA[<p>Once upon a time`stamp`, in a `data`base far far away, someone filed a bug named: `Microseconds precision is not retained by TIME, DATETIME, and TIMESTAMP field types.` &#8211; Bug Number 8523. This was the beginning of 2005, yet now that we are approaching the end of 2009, after 4.5 years, many (including myself) are still asking for this.</p>
<p>In fairness sake, MySQL have indeed supplied a way to retain milli and micro seconds in a decimal field `DECIMAL(17,3)`, and it is also queryable as if it were a timestamp BUT why isn&#8217;t it possible to store in a `DATETIME` or `TIMESTAMP` field? Why can&#8217;t we run a &#8217;select now()&#8217; or &#8217;select curtime()&#8217; etc and get a full timestamp including milli / micro seconds?</p>
<p>I have counted 37 different usernames asking for this feature, spanning from 15th Feb 2005 to recently. (list found below)</p>
<p>Some have suggested UDFs, others suggested using log4j while others, pretty annoyed, allegedly went to MS SQL and some to Postgres :). The comments were varied but one thing was quite common &#8230; a feeling of frustration and or disappointment, probably because despite all the requests for the feature in question to be implemented, it is still missing.</p>
<p>Back in 2007, <a href="http://feedblog.org" target="_blank"> Kevin Burton </a> also tried to understand why MySQL doesn&#8217;t support milliseconds <a href="http://feedblog.org/2007/05/26/why-doesnt-mysql-support-millisecond-datetime-resolution/" target="_blank">here</a>. <a href="http://krow.net/" target="_blank">Brian Aker </a>gave his view on the matter (back in 2007) in the first comment on the same blog post.</p>
<p>My point is (yeah about time :)) &#8230;. this is quite an important feature!! and I&#8217;m hoping a few MySQL developers / project managers / community people might read this blog post and maybe give it some more importance.</p>
<p>Now from the technical side, I am going to describing a way, `someone from MySQL has suggested it to me this week` to store milli and micro seconds. Maybe it&#8217;ll help you work your milliseconds requirement out (or maybe not). As to the way to generate milli and micro seconds, there is a UDF written by Mr Wadimoff <a href="http://bugs.mysql.com/bug.php?id=8523" target="_blank">here</a> which you might use.</p>
<p>Storing:</p>
<blockquote><p><code lang="sql"><br />
mysql> create table ttable<br />
    -> (<br />
    ->    timecol decimal(17,3)<br />
    -> ) Engine=MyISAM;<br />
Query OK, 0 rows affected (0.04 sec)</p>
<p>mysql> insert into ttable (timecol) values( 20081223094234.572);<br />
Query OK, 1 row affected (0.00 sec)</p>
<p>mysql> insert into ttable (timecol) values( 20090806133004.132);<br />
Query OK, 1 row affected (0.00 sec)</p>
<p>mysql> insert into ttable (timecol) values( 20100411011258.985);<br />
Query OK, 1 row affected (0.00 sec)</p>
<p>mysql> insert into ttable (timecol) values( 20110411011258.985);<br />
Query OK, 1 row affected (0.00 sec)</p>
<p>mysql> select timestamp(timecol) from ttable;<br />
+----------------------------+<br />
| timestamp(timecol)         |<br />
+----------------------------+<br />
| 2008-12-23 09:42:34.572000 |<br />
| 2009-08-06 13:30:04.132000 |<br />
| 2010-04-11 01:12:58.985000 |<br />
| 2011-04-11 01:12:58.985000 |<br />
+----------------------------+<br />
4 rows in set (0.00 sec)</p>
<p>mysql> select timecol from ttable where timecol < "20090901000000";<br />
+--------------------+<br />
| timecol            |<br />
+--------------------+<br />
| 20081223094234.572 |<br />
| 20090806133004.132 |<br />
+--------------------+<br />
2 rows in set (0.00 sec)</p>
<p>mysql> select timecol from ttable where timecol > "20090901000000";<br />
+--------------------+<br />
| timecol            |<br />
+--------------------+<br />
| 20100411011258.985 |<br />
| 20110411011258.985 |<br />
+--------------------+<br />
2 rows in set (0.00 sec)</p>
<p>mysql> select timecol from ttable where timecol > now();<br />
+--------------------+<br />
| timecol            |<br />
+--------------------+<br />
| 20100411011258.985 |<br />
| 20110411011258.985 |<br />
+--------------------+<br />
2 rows in set (0.00 sec)</p>
<p>mysql> select datediff(20110411011258.985,20100411011258.985);<br />
+-------------------------------------------------+<br />
| datediff(20110411011258.985,20100411011258.985) |<br />
+-------------------------------------------------+<br />
|                                             365 |<br />
+-------------------------------------------------+<br />
1 row in set (0.00 sec)</p>
<p>mysql> select timecol, timestamp(timecol) as timestamp ,year(timecol) as year, month(timecol) as month, day(timecol) as day,quarter(timecol) as quarter from ttable;<br />
+--------------------+----------------------------+------+-------+------+---------+<br />
| timecol            | timestamp                  | year | month | day  | quarter |<br />
+--------------------+----------------------------+------+-------+------+---------+<br />
| 20081223094234.572 | 2008-12-23 09:42:34.572000 | 2008 |    12 |   23 |       4 |<br />
| 20090806133004.132 | 2009-08-06 13:30:04.132000 | 2009 |     8 |    6 |       3 |<br />
| 20100411011258.985 | 2010-04-11 01:12:58.985000 | 2010 |     4 |   11 |       2 |<br />
| 20110411011258.985 | 2011-04-11 01:12:58.985000 | 2011 |     4 |   11 |       2 |<br />
+--------------------+----------------------------+------+-------+------+---------+<br />
4 rows in set (0.00 sec)</p>
<p></code></p></blockquote>
<p>Bug link: <a href="http://bugs.mysql.com/bug.php?id=8523" target="_blank">http://bugs.mysql.com/bug.php?id=8523<br />
</a></p>
<blockquote><p>
<strong>List of people asking for this feature:</strong></p>
<p>[15 Feb 2005 21:47] Christopher Miller<br />
[03 May 2005 19:46] Boris Burtin<br />
[30 Jun 2005 10:52] Yoshiaki Tajika<br />
[06 Mar 2006 22:14] Tim Sheehy<br />
[14 Mar 2006 21:50] Oriol Garrote<br />
[17 Aug 2006 22:15] Sami Shalabi<br />
[01 Apr 2007 05:22] Ben Valentine<br />
[02 Apr 2007 23:25] Eric George<br />
[27 Apr 2007 06:10] Verghese Mappillai<br />
[23 May 2007 20:47] Andrew McLaughlin<br />
[25 May 2007 18:24] Stephen Pietrowicz<br />
[31 May 2007 10:51] harjeev chug<br />
[22 Jun 2007 01:17] Peter McCulloch<br />
[20 Jul 2007 16:42] Daren Schwenke<br />
[03 Aug 2007 04:45] Jean-Guy Mossu<br />
[20 Feb 2008 09:32] bodri bodri<br />
[11 Mar 2008 20:12] Nathan Atkinson<br />
[24 Mar 2008 08:35] Sourav Sipani<br />
[02 Jul 2008 05:03] Michael Haselton<br />
[22 Aug 2008 10:32] Aniruddha Shival<br />
[28 Aug 2008 17:37] Jorge Urdaneta<br />
[29 Aug 2008 22:19] Ben Wern<br />
[05 Sep 2008 10:41] Pavel Alexeev<br />
[19 Dec 2008 14:31] Felix Dierich<br />
[09 Feb 2009 07:58] Gabriele Tozzi<br />
[17 Feb 2009 23:20] Paul Craven<br />
[21 Feb 2009 12:55] Thomas Ene<br />
[27 Feb 2009 12:13] Pascal Calovini<br />
[09 Mar 2009 09:03] Siu Ching Pong (Asuka Kenji)<br />
[12 Mar 2009 19:41] Yu Chen<br />
[02 Apr 2009 02:35] Noel Akins<br />
[02 Apr 2009 13:09] Lars Monsees<br />
[19 Apr 2009 17:30] Ryan Shillington<br />
[22 Apr 2009 09:00] Jeff Peff<br />
[04 May 2009 09:30] alastair knowles<br />
[28 May 2009 11:42] Yuri Kirilin<br />
[31 May 2009 04:37] Peter Thairu
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/08/once-upon-a-timestampmilliseconds/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
