<?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>underdog-blog &#187; mysql</title>
	<atom:link href="http://blog.underdog-projects.net/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.underdog-projects.net</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 23 Oct 2010 18:43:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>generate random timestamps in mysql</title>
		<link>http://blog.underdog-projects.net/2008/10/generate-random-timestamps-in-mysql/</link>
		<comments>http://blog.underdog-projects.net/2008/10/generate-random-timestamps-in-mysql/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 10:13:15 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[random timestamp]]></category>

		<guid isPermaLink="false">http://blog.underdog-projects.net/?p=16</guid>
		<description><![CDATA[I&#8217;m now try to prepare a mysql performance comparison between hdd and flash. So to create a lot of test data I needed a function to create random timestamps in a certain range. After trying google I gave up and started with the mysql documentation and came up with the following statement: select from_unixtime( unix_timestamp('2008-01-01 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m now try to prepare a mysql performance comparison between hdd and flash. So to create a lot of test data I needed a function to create random timestamps in a certain range.</p>
<p>After trying google I gave up and started with the mysql documentation and came up with the following statement:</p>
<pre class="prettyprint lang-sql">select from_unixtime(
       unix_timestamp('2008-01-01 01:00:00')+floor(rand()*31536000)
);</pre>
<p>So lets break it it down a bit:</p>
<p>first I set a start date (minimum for the random)</p>
<blockquote><p>unix_timestamp(&#8217;2008-01-01 01:00:00&#8242;)</p></blockquote>
<p>now you have the timestamp in Unix timestamp format. This means you can add any given seconds interval to it.</p>
<blockquote><p>rand()*31536000</p></blockquote>
<p>For me I wanted a value between 2008 and 2009 (one year: 60 seconds * 60 minutes * 24 hours * 365 days = 31536000). Because the Unix timestamp doesn&#8217;t support fractions your need to round the value to an int. (floor or round the value).</p>
<p>After the addition you just convert it back from Unix timestamp to a mysql timestamp.</p>
<p>so here the generic formular:</p>
<pre class="prettyprint lang-sql">select from_unixtime(
      unix_timestamp( 'start timestamp')
     +floor(rand()* (max interval in seconds) )
);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.underdog-projects.net/2008/10/generate-random-timestamps-in-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

