<?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 Services for Turnkey Web Solutions</description>
	<lastBuildDate>Thu, 10 May 2012 02:17:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</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 well documented (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html), 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. The application is for an auction website, where I am comparing the current [&#8230;] <a class="more-link" href="http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/">&#8595; Read the rest of this entry...</a><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--><div class="linkedin_share_container" style="float:right;margin:0px 0px 10px 10px"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwebpaws.com%2Fblog%2F81%2Fmysql-time-comparing-time-date-entries%2F&amp;title=MySQL+Time%2C+comparing+time+date+entries&amp;summary=MySQL+time+and+date+functions+are+well+documented+%28http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.1%2Fen%2Fdate-and-time-functions.html%29%2C+but+the+applications+for+specific+needs+are+not.++I+would+like+to+share+a+tidbit+about+comparing+two+database+date+entries%2C+or+one+entry+to+the+current+time+and+then+comparing+the+difference.%0AThe+application+is+for+an+auction+website%2C+where+I+am+comparing+the+current+%5B%26hellip%3B%5D+%3Ca+class%3D%22more-link%22+href%3D%22http%3A%2F%2Fwebpaws.com%2Fblog%2F81%2Fmysql-time-comparing-time-date-entries%2F%22%3E%26darr%3B+Read+the+rest+of+this+entry...%3C%2Fa%3E&amp;source=WebPaws.com" onclick="return popupLinkedInShare(this.href,'console',400,570)" class="linkedin_share_button"><img src="http://webpaws.com/blog/wp-content/plugins/linkedin-share-button/buttons/01.png" alt="" /></a></div><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><span class="facebook-like"><fb:like layout="box_count" show_faces="false" width="45" href="http://webpaws.com/blog/81/mysql-time-comparing-time-date-entries/"></fb:like></span>]]></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>

