I have to compare datetime object with php, $availability
is an array of dates that contains (from: 2017-07-24 16:20:08.000000
to 2017-07-25 16:20:08.000000
) and when is 2017-07-23 16:20:08.000000
.
/// when : 2017-07-23
$when = DateTime::createFromFormat( 'Y-m-d', '2017-07-23' );
// from : 2017-07-24
$from = DateTime::createFromFormat( 'Y-m-d', '2017-07-24' );
// to : 2017-07-25
$to = DateTime::createFromFormat( 'Y-m-d', '2017-07-25' );
if ( $when >= $from && $when <= $to ) { echo $when . "is between from and to"; }
This doesn't work, or did I miss something?
How to compare objects from DateTime::createFromFormat
? Is it possible, or do I have to strtotime
?