Reputation: 9797
I have a timestamp in a MySql database. The format is: 2018-08-28 12:39:59
I want to select different periods of time. I have problems with the time part. For instance:
$begin = strtotime("first day of this month midnight");
$begin = date("Y-m-d h:i:s", $begin);
If I echo $begin it gives me: 2018-08-01 12:00:00
So, it does not includes for instance: 2018-08-01 01:00:00
I have been searching and the official documentation says:
'midnight' The time is set to 00:00:00
http://php.net/manual/en/datetime.formats.relative.php
How to include the whole first day in the begin variable? (begin from 0 or ignore time)
Upvotes: 0
Views: 33
Reputation: 3237
PHP's date function has two different modifiers: H and h h displays hour in a 12-hour format (so midnight is 12... if you added the AM/PM modifier you'd see 12:00:00 am)
try
$begin = date("Y-m-d H:i:s", $begin);
The will output 00:00:00 as you expect
Upvotes: 1
Reputation: 7609
You are using the wrong hour format, you should do:
// uppercase H --v
$begin = date("Y-m-d H:i:s", $begin);
// Output: 2018-08-01 00:00:00
echo $begin;
From the documentation:
h
: 12-hour format of an hour with leading zerosH
: 24-hour format of an hour with leading zerosUpvotes: 1