Conditional statement for dates
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.';
}
?
Topic conditional-tags comparison php Wordpress
Category Web