Page 1 of 1

Timestamp and Query Question

Posted: Tue Feb 28, 2006 2:02 pm
by idotcom
Hi All


I have a table in mysql that stores messages sent. The table uses int(10) for a timestamp that is set by php when a message is sent.

Time stamps look like this: 1141154900

I need to do something like:

SELECT * FROM message_table WHERE timestamp = todays date (date only not time) AND userid = $current_user

if(result num rows > 5) exit....

The purpose is to select all messages sent by user today (within 24 hours) and if results greater than 5, to exit;

How do I go about comparing todays date against timestamp rows in a table?


Any help from you guru's would be greatly appreciated! :D

Thank you.

Posted: Tue Feb 28, 2006 2:06 pm
by chrys

Code: Select all

$today = strtotime(date("Y-m-d ") . "00:00:00");
$tmrw = strtotime(date("Y-m-d", strtotime("+1 day")) . "00:00:00");

$sql = "SELECT FROM table WHERE timestamp >= $today AND timestamp < $tmrw";
You get the point

Posted: Tue Feb 28, 2006 2:11 pm
by idotcom
Geez how simple is that... :lol:

Thank you much!

Posted: Tue Feb 28, 2006 2:43 pm
by idotcom
Just a note to the difference.

This didn't work.

Code: Select all

$today = strtotime(date("Y-m-d ") . "00:00:00"); 
$tmrw = strtotime(date("Y-m-d", strtotime("+1 day")) . "00:00:00"); 

$sql = "SELECT FROM table WHERE timestamp >= $today AND timestamp < $tmrw";
However this did.

Code: Select all

$today = mktime(0, 0, 0, date("m"), date("d"), date("y")); 
$tmrw = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));

$sql = "SELECT FROM table WHERE timestamp >= $today AND timestamp < $tmrw";
Thanks again though :D Everything works like I need it now!

Posted: Tue Feb 28, 2006 2:44 pm
by chrys
That's good, I prolly made some small mistake :/