MyBB Community Forums

Full Version: MySQL question: Select rows inserted today
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The column "date_added" holds the time the record was inserted in unix epoch format. Which query would I use to select rows that were inserted today (the day the query is run), since midnight? I found a few tutorials online, but they all require the date to be stored in YYYY-MM-DD format, which is frankly a dumb way of storing dates.

The best I can get is number of rows inserted in the last 24 hours, but that's useless to me.

Thanks!
The hardest part of this would be determining when midnight was Smile after that you can just use WHERE
You can use php's mktime to get the unix time for any date, in this case midnight today. You can then use that as a reference to get rows since then.

$dE = date("n-j-Y", time());
$d = explode("-", $dE);
$midnight = mktime(0,0,0,$d[0],$d[1],$d[2]);

// SQL
SELECT * FROM <table> WHERE `date_added` > {$midnight}

Note: The above is not tested code, just a theoretical brainstorm.
Thank you and +rep.