Answers for "compare two date strings php"

PHP
7

php compare two dates

$today = date("Y-m-d");
$expire = $row->expireDate; //from database

$today_time = strtotime($today);
$expire_time = strtotime($expire);

if ($expire_time < $today_time) { /* do Something */ }
Posted by: Guest on December-15-2019
2

php date compare with today

<?php

$datetime1 = new DateTime('2009-10-11 12:12:00');
$datetime2 = new DateTime('2009-10-13 10:12:00');

if ($datetime1 > $datetime2) {
    echo 'datetime1 greater than datetime2';
}

if ($datetime1 < $datetime2) {
    echo 'datetime1 lesser than datetime2';
}

if ($datetime1 == $datetime2) {
    echo 'datetime2 is equal than datetime1';
}
Posted by: Guest on February-24-2021
2

php compare dates

$date_now = date("Y-m-d h:i:s");
$variable = new DateTime($date_now);
$to_compare = "2018-06-01 12:48:09";
$variable1 = new DateTime($to_compare);
$difference = date_diff($variable, $variable1)->format("Difference => %Y years, %m months, %d days, %h hours, and %i minutes");
echo $difference;
Posted by: Guest on June-12-2021

Browse Popular Code Answers by Language