I’m modifying a WordPress plugin that another dev wrote a couple years back. In the PHP code, he’s created a $now
variable to get the current time. Then further down, we’re displaying a list of content filtered in ascending order. The problem I’m running into is that if there are multiple posts on the same day, it’s not filtering them in ascending order according to the hours and minutes; only the day.
You can see what I’m talking about here: http://alhughesauction.com/upcoming-auctions
The first two auctions are on the same day, but the second one should actually display first since it’s at 11am and the other is at 3pm.
This is how the $now
is defined:
$now = "'" . date("Y-m-d", strtotime("now-5hours")) . "'";
As per the PHP manual, I tried adding -g
to "Y-m-d"
, but that didn’t work.
Here is where we’re grabbing the data from the database:
$sql = "SELECT * FROM " . AH_DATA . " WHERE date >= {$now} ORDER BY date ASC" . $limit;
I would venture to guess that I simply need to get the $now
variable to add hours and minutes, but I’m still learning the ropes of PHP 🙂
As Bhumi said use
date("Y-m-d H:i:s");
for$now
Also the datatype of
date
column should betimestamp
, if it is not use this query for ordering in ascending orderdate
is reserved word inmysql
use`
around column name to use it like column nameEdit
Try this query