Maybe you can help me.
I need to improve this functionality to check the date in ACF with the real date and output different function values. When event date end return "END" or "0". Else return "cont" or "1"
Unfortunately, it absolutely does not want to check the dates)
function add_calendar() {
$cur_date = date("YmdTHisZ", time());
$starttime = date('YmdTHisZ', strtotime(get_field('start')));
$endtime = date('YmdTHisZ', strtotime(get_field('end')));
$title = get_the_title();
if($cur_date <= $endtime){
$string = "https://calendar.google.com/calendar/render?action=TEMPLATE&dates=" . $starttime . "%2F" . $endtime . "&details=&location=&text=" . $title;
return $string;
} else {
return "#";
}
}
2
Answers
Solution
I haven’t tested this but you might try using PHP’s
DateTime()
class. It’s more reliable and I believe it supports date comparisons in the way you’re using: