-1

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’)

}
  • Does this answer your question? [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Markus Zeller Nov 17 '21 at 16:35
  • I don't think so. It seems like exactly what I'm doing with mine, it just isn't working. Thanks anyway! – May Hitchings Nov 17 '21 at 21:08

1 Answers1

0

Try like this one set date_default_set to your country GMT
<?php date_default_timezone_set("Asia/Colombo"); $time = date('H:i:s',time()); ?>