Page 1 of 1
how to find topic posted today in php /mysql
Posted: Fri Sep 15, 2006 6:06 am
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
Posted: Fri Sep 15, 2006 7:03 am
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)

Posted: Fri Sep 15, 2006 8:32 am
by rami
i solved it
i did
select * from table where date(postedon)=curdate();
thanks for reply any way