$this->today = date('Y-m-d') . '00:00:00';
Would do the trick.
Question
I need to retrieve a date of this format 2014-17-02 00:00:00
, where the hours minutes and seconds are just zeros, meaning I want today as the day started after midnight, or yesterday 2014-16-02 23:59:59pm
depending on how you look at it.
The reason I want to retrieve this kind of datetime is so that I can effectively compare my 'created' field inside the database, allowing me to obtain records inserted 'today'..
Any suggestions? I have tried these:
$this->today = date('Y-m-d H:i:s');
$this->today = date('Y-m-d H:i:s',strtotime('now'));
But they seem to do the same thing(give me datetime in accuracy of hh mm ss) which is not what I want.
I want to execute this query
"SELECT users.role as user_role,
Count(users.role) AS user_count
FROM users
WHERE users.created >= '$this->today' // any record created after yest midnight
GROUP BY users.role"
Solution
$this->today = date('Y-m-d') . '00:00:00';
Would do the trick.
OTHER TIPS
It is also possible to calculate this purely using SQL - one less clock to worry about.
SELECT ....
WHERE users.created >= NOW() - INTERVAL 1 DAY
SELECT users.role as user_role,
Count(users.role) AS user_count
FROM users
WHERE DATE(users.created) >= '$this->today'
GROUP BY users.role
$this->today = date('Y-m-d H:i:s');
i think replace this with
$this->today = date('Y-m-d', strtotime("-1 days")); // get yesterday date to