So I've broken this down to its simplest components and I'm still stuck. I've never dealt with dates and times in PHP before. I'm using ACF to set date and time for a webinar landing page template. I need the date to only print if it's in the future.
The initial time is coming in using g:i a format from ACF. The date is coming in as F j, Y.
$webinar_date = get_field(‘webinar_date’);
$webinar_time = get_field(‘webinar_time’);
$old_datetime = strtotime(‘$webinar_date $webinar_time’);
$new_datetime = date(‘Y-m-d H:i:s’, $old_datetime);
$now = date(‘Y-m-d H:i:s’);
if($new_datetime >= $now) {
echo get_field(‘webinar_date’);
echo get_field(‘webinar_time’);
}
It was working fine when I was using the below code to just compare date, so I think something with my time formatting is off.
$webinar_date = get_field(‘webinar_date’);
$today = date(‘Y-m-d’);
$old_date = strtotime($webinar_date);
$new_date = date(‘Y-m-d’ , $old_date);
if($new_date >= $today) {
echo get_field(‘webinar_date’)
}