<?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; migrating to mysql</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/tag/migrating-to-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>Because Sharing is Caring</description>
	<lastBuildDate>Mon, 26 Sep 2011 23:34:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Datetime &amp; Timestamp manipulation / migration explained</title>
		<link>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 16:47:16 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[date_format]]></category>
		<category><![CDATA[microsecond]]></category>
		<category><![CDATA[migrating to mysql]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[millisecond]]></category>
		<category><![CDATA[mysql millisecond]]></category>
		<category><![CDATA[str_to_date]]></category>
		<category><![CDATA[timstamp]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=351</guid>
		<description><![CDATA[Are you doing some datetime manipulation or maybe you are migrating from some database technology to MySQL or possibly using milliseconds? Here is an example on how to go about it: Say you have the following date: MAR 16 2008 09:12:51:893AM SELECT DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893AM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&#62; 2008031691251.893000 What if its PM [...]]]></description>
			<content:encoded><![CDATA[<p>Are you doing some datetime manipulation or maybe you are migrating from some database technology to MySQL or possibly using milliseconds?<br />
Here is an example on how to go about it:</p>
<p>Say you have the following date: MAR 16 2008 09:12:51:893AM<br />
<code>SELECT DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893AM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&gt; 2008031691251.893000<br />
</code></p>
<p>What if its PM rather than AM<br />
<code>SELECT DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893PM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&gt; 20080316211251.893000<br />
</code></p>
<p>Ok so this is just simple string manipulation where:<br />
<code>%M is the month name<br />
%d is day number<br />
%Y is the year<br />
%h is the hour<br />
%i is the minute<br />
%s is the second<br />
%f is the microsecond<br />
%p is the period: ante or post meridiem</code><br />
In the DATE_FORMAT part we se a %k which is in 24hr format in order to loose the period.</p>
<p>A more detailed list is found <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format" target="_blank">here</a></p>
<p>Here is a demo:</p>
<p><code>mysql Tue Jun 15 12:32:37 2010 &gt; CREATE TABLE test.abc(a DECIMAL(17,3)) ENGINE=MYISAM;<br />
Query OK, 0 rows affected (0.03 sec)</code></p>
<p><code>mysql Tue Jun 15 12:32:45 2010 &gt; INSERT INTO abc VALUES ( DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893PM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f') );<br />
Query OK, 1 row affected (0.01 sec)</code></p>
<p><code>mysql Tue Jun 15 12:32:51 2010 &gt; SELECT * FROM abc;<br />
+--------------------+<br />
| a                  |<br />
+--------------------+<br />
| 20080316211251.893 |<br />
+--------------------+<br />
1 row in set (0.00 sec)</p>
<p></code></p>
<p><code>mysql Tue Jun 15 12:32:56 2010 &gt; SELECT TIMESTAMP(a) FROM abc;<br />
+----------------------------+<br />
| TIMESTAMP(a)               |<br />
+----------------------------+<br />
| 2008-03-16 21:12:51.893000 |<br />
+----------------------------+<br />
1 row in set (0.00 sec)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

