how to find topic posted today in php /mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

how to find topic posted today in php /mysql

Post by rami »

i have postedon field as timestamp
i was doing
select * from table where postedon=curdate();
to find total post ,posted today
but it returns no thing though there are rows which match that condition...

any idea of doing it
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

using a timestamp is kind of limiting, if you were using a datetime field it would be much easier to do this SQL side. In your case of using a timestamp, to be accurate you want to grab the first second of today and simply check if any dates are greater than that.

You can use this function getFirstSecond(); in combination with

Code: Select all

mysql_query('SELECT * FROM `table` WHERE `timestamp` > \''. getFirstSecond(); .'\' ORDER BY `timestamp`DESC') or die(mysql_error());
You may be able to play with UNIX_TIMESTAMP and INTERVAL to get it all SQL if you wish, I just can't right now (too early) :wink:
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

Post by rami »

i solved it
i did
select * from table where date(postedon)=curdate();
thanks for reply any way
Post Reply