<?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>LAMP with ·dotmanila &#187; default datetime value</title>
	<atom:link href="http://dotmanila.com/blog/tag/default-datetime-value/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotmanila.com/blog</link>
	<description>Linux Security, Apache Tuning, MySQL Optimization and PHP Programming</description>
	<lastBuildDate>Sun, 01 Aug 2010 01:54:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL Default DATETIME Value &#8211; A Quick Rant</title>
		<link>http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/</link>
		<comments>http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 16:39:22 +0000</pubDate>
		<dc:creator>jervin</dc:creator>
				<category><![CDATA[BSD/Mac OSX]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[default datetime value]]></category>
		<category><![CDATA[now()]]></category>

		<guid isPermaLink="false">http://dotmanila.com/blog/?p=106</guid>
		<description><![CDATA[I was reviewing a year old code which I am adding a feature to. It so happened I came to a familiar issue about having two timestamp/datetime columns, one which should have the CURRENT_DATE / NOW() as default value and the other with an 'ON UPDATE CURENT_TIMESTAMP'. Examine the simple structure below: CREATE TABLE `stories` [...]]]></description>
			<content:encoded><![CDATA[<p>I was reviewing a year old code which I am adding a feature to. It so happened I came to a familiar issue about having two timestamp/datetime columns, one which should have the CURRENT_DATE / NOW() as default value and the other with an 'ON UPDATE CURENT_TIMESTAMP'. Examine the simple structure below:<br />
<code><br />
CREATE TABLE `stories` (<br />
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,<br />
`title` VARCHAR( 255 ) NOT NULL ,<br />
`text` TEXT NOT NULL ,<br />
`creationdate` DATETIME NOT NULL ,<br />
`lastupdate` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP<br />
) ENGINE = MYISAM</code></p>
<p>When you want to store stories, you would also want to record when it was originally created as well track the last time it was updated. The problem here is that adding a `DEFAULT NOW()` clause will not work for the `CREATE TABLE` query above as it is not supported. So when your insert a new story you will have to explicitly add a `NOW()` function for the `creationdate` row so it will reflect the current date as creation date. This should've been a simple schema functionality, turns out after more than a year MySQL seems to ignore for some reason.</p>
<p>Go on have yourself a read here http://bugs.mysql.com/bug.php?id=27645</p>
<p>How about you, how many times have you have to work around this from your application code?</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-blogger">
			<a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/&amp;n=MySQL+Default+DATETIME+Value+-+A+Quick+Rant&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/&amp;title=MySQL+Default+DATETIME+Value+-+A+Quick+Rant" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/&amp;t=MySQL+Default+DATETIME+Value+-+A+Quick+Rant" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=MySQL+Default+DATETIME+Value+-+A+Quick+Rant&amp;body=Link: http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A I%20was%20reviewing%20a%20year%20old%20code%20which%20I%20am%20adding%20a%20feature%20to.%20It%20so%20happened%20I%20came%20to%20a%20familiar%20issue%20about%20having%20two%20timestamp%2Fdatetime%20columns%2C%20one%20which%20should%20have%20the%20CURRENT_DATE%20%2F%20NOW%28%29%20as%20default%20value%20and%20the%20other%20with%20an%20%27ON%20UPDATE%20CURENT_TIMESTAMP%27.%20Examine%20the%20simple%20structure%20belo" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/&amp;title=MySQL+Default+DATETIME+Value+-+A+Quick+Rant" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/&amp;title=MySQL+Default+DATETIME+Value+-+A+Quick+Rant&amp;summary=I%20was%20reviewing%20a%20year%20old%20code%20which%20I%20am%20adding%20a%20feature%20to.%20It%20so%20happened%20I%20came%20to%20a%20familiar%20issue%20about%20having%20two%20timestamp%2Fdatetime%20columns%2C%20one%20which%20should%20have%20the%20CURRENT_DATE%20%2F%20NOW%28%29%20as%20default%20value%20and%20the%20other%20with%20an%20%27ON%20UPDATE%20CURENT_TIMESTAMP%27.%20Examine%20the%20simple%20structure%20belo&amp;source=LAMP with ·dotmanila" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/&amp;title=MySQL+Default+DATETIME+Value+-+A+Quick+Rant" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=MySQL+Default+DATETIME+Value+-+A+Quick+Rant+-+http://b2l.me/adk2nj&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://dotmanila.com/blog/2009/11/mysql-default-datetime-value-a-quick-rant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
