Im trying to create a conditional statement comparing two dates. I have a ACF custom date field as one date, and then comparing against the current date.
Below is what i have and iv echoed both $date and $currentdate and they both come out in the same format, so im not sure why it wont work. They both output in the format like: 20170105 which i beleive they need to be to compare.
<?php
$currentdate = current_time('Ymd');
$date = get_field('course_start_date', false, false);
$date = new DateTime($date);
if ($currentdate > $date) {
echo ' - Started.';
} else {
echo ' - Not started.';
}
?>
echo
or do aprint_r
on$date
and give the value please.course_start_date
? Why do you post in your comment integer values saying they are returned bycurrent_time()
andDateTime
when those functions return strings? Please, edit the question to add additional information.