最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

advanced custom fields - Comparing two dates (ACF and current time)

programmeradmin2浏览0评论

I’m trying to compare two dates (the current date with an ACF datepicker one) to display specific content. What I’m trying to achieve is to display a phrase if the ACF date is lower than the current time (in few words if a service is expired). This is my code:

$dataScadenza = get_field('data_di_scadenza');
$currentDateTime = date('d.m.y');

if($dataScadenza <= $currentDateTime) {

echo '<a href="'.get_field('link_esito').'">';
echo '<button class="vedi_esiti">VEDI ESITI</button>';
echo '</a>';

} else {

echo '<span class="ds_label">data scadenza</span>';
echo '<div class="ds_date">'.get_field('data_di_scadenza').'</div>';

}

where $dataScadenza is the ACF date and $currentDateTime is current date. Both variables have the same output (d.m.y).

What happens is that the comparison is applied only on day number and not on the entire date.

Anyone can help to solve the problem?

Thank you!

发布评论

评论列表(0)

  1. 暂无评论