»
S
I
D
E
B
A
R
«
+
More
Recent News and Links
  • No bookmarks avaliable.
Informational Website Poll
Mar 25th, 2009 by webpaws

Vote and or view this poll on what is most important to a visitor to an information website.

Thank you for your interest and support.

VN:F [1.8.5_1061]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.5_1061]
Rating: 0 (from 0 votes)
 
Take a piece of the Web from WebPaws.com: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • MisterWong
  • Y!GG
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • De.lirio.us
  • eKudos
  • email
  • Facebook
  • Fleck
  • Google Bookmarks
  • Hype
  • LinkedIn
  • MySpace
  • Print
  • Technorati
  • YahooMyWeb
MySQL Time, comparing time date entries
Mar 11th, 2009 by webpaws

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 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.

My PHP code sets a MySQL variable to insert into the SQL statement to compare the end or beginning timestamp.


//In PHP, depending on the search query, I set the SQL to compare the beginning timestamp or the ending timestamp.


if($cat==1){$catsql="TIMESTAMPDIFF(HOUR,StartTime,Now()) < '24'";}
elseif($cat==2){$catsql="TIMESTAMPDIFF(HOUR,Now(),EndTime) < '24'";}
else{$catsql="";}

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.

Keep in mind that the time date format is important and should be in the following format for the above MySQL statements to work:


$currenttime = date("Y-m-d H:i:s"); //PHP timestamp consitant with MySQL

VN:F [1.8.5_1061]
Rating: 9.5/10 (2 votes cast)
VN:F [1.8.5_1061]
Rating: 0 (from 0 votes)
 
Take a piece of the Web from WebPaws.com: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • MisterWong
  • Y!GG
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • De.lirio.us
  • eKudos
  • email
  • Facebook
  • Fleck
  • Google Bookmarks
  • Hype
  • LinkedIn
  • MySpace
  • Print
  • Technorati
  • YahooMyWeb
»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright by WebPaws.com 2009. All Rights Reserved.

WebPaws.com is Digg proof thanks to caching by WP Super Cache