Let's say I have the following dates/datetimes. How can I best tell which ones are at midnight (i.e. time is 00:00:00)? The first one should not be midnight, but the next three should be. Thanks
$d1=new DateTime('12/10/2012 05:33');
$d2=new DateTime('12/10/2012');
$d3=new DateTime('12/10/2012 00:00');
$d4=new DateTime('12/10/2012 00:00:00');
Check if the hour and minute are both zero:
if( $date->format( 'H') == 0 && $date->format( 'i') == 0) {
echo "Midnight!";
}
You will have to specify the time zone and use DateTime
$test = new DateTime('NOW', new DateTimeZone('Asia/Kolkata'));
$h=$test->format('H');
$m=$test->format('i');
$s=$test->format('s');
if( $h == 0 && $m==0 && $s == 0) {
echo "Midnight!";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With