<?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>WebPaws.com &#187; comparing time</title>
	<atom:link href="http://webpaws.com/blog/tag/comparing-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://webpaws.com/blog</link>
	<description>Internet Marketing and Design</description>
	<lastBuildDate>Tue, 15 Jun 2010 11:43:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>MySQL Time, comparing time date entries</title>
		<link>http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/</link>
		<comments>http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 21:49:25 +0000</pubDate>
		<dc:creator>webpaws</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[auction time]]></category>
		<category><![CDATA[comparing time]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[ending soon]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[Timestamp]]></category>

		<guid isPermaLink="false">http://webpaws.com/blog/2009/03/11/mysql-time-comparing-time-date-entries/</guid>
		<description><![CDATA[MySQL time and date functions are [...]<br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://webpaws.com/blog/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br /><p><a href="http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/">MySQL Time, comparing time date entries</a> is a post from: <a href="http://webpaws.com/blog">WebPaws.com</a></p>
]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>MySQL time and date functions are well documented (<a title="MySQL Timestamp, date, time manual" href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html" target="_blank">http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html</a>), but the applications for specific needs are not.  I would like to share a tidbit about comparing two database date entries, or one entry to the current time and then comparing the difference.</p>
<p>The application is for an auction website, where I am comparing the current time to either the ending time date or the beginning time date to determine how many hours the current time is from either of those timestamps.</p>
<p>My PHP code sets a MySQL variable to insert into the SQL statement to compare the end or beginning timestamp.</p>
<p><code><br />
//In PHP, depending on the search query, I set the SQL to compare the beginning timestamp or the ending timestamp.</code><br />
<code><br />
if($cat==1){$catsql="TIMESTAMPDIFF(HOUR,StartTime,Now()) &lt; '24'";}<br />
elseif($cat==2){$catsql="TIMESTAMPDIFF(HOUR,Now(),EndTime) &lt; '24'";}<br />
else{$catsql="";}<br />
</code><br />
In the SQL code, I am finding the difference in Hours from the current time Now() to either the EndTime or the StartTime timestamps.  If less then 24 hours, it allows a condition to occur in the SQL statement to select specific records meeting that condition.</p>
<p>Keep in mind that the time date format is important and should be in the following format for the above MySQL statements to work:</p>
<p><code><br />
$currenttime = date("Y-m-d H:i:s");  //PHP timestamp consitant with MySQL<br />
</code></p>
<br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://webpaws.com/blog/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br /><p><a href="http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/">MySQL Time, comparing time date entries</a> is a post from: <a href="http://webpaws.com/blog">WebPaws.com</a></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
