ACF 日期选择器添加一年

ACF date-picker add one year

我有一个问题,我正在将 ACF 4.4.12.1 与 wordpress 一起使用,我想将 1 年添加到使用转发器字段创建的日期。

在前台,我显示了一个名为 "first-date" 的日期:

<?php the_sub_field('first-date'); ?>(字段类型日期选择器)

现在我想显示另一个日期,它显示与 "first-date" 相同的日期,但增加了一年。

我正在尝试做类似的事情:

<?php
echo $date_debut    =   the_sub_field('first-date');
$date_expire    =   $date_debut;

$nbre=365;
$tmp=split('-', $date_expire);
$jour = $tmp[2]; 
$mois = $tmp[1]; 
$annee = $tmp[0]; 

$date_expiration = mktime($jour, $mois , $annee)+ 24*3600*$nbre;
echo '<br />'.date("d-m-Y", $date_expiration);

但我恢复了值 01-01-1971 有人可以帮助我吗?

谢谢

试试这个:

// $date_debut = 17/01/2018 for example
$date_debut = get_sub_field('first-date'); 

// Need to replace the slash by a dash
$date_debut = strtotime(str_replace('/', '-',$date_debut));

$date_expiration = date("d-m-Y", strtotime(" + 1 year", $date_debut ));

echo '<br />'.$date_expiration; 
// Display: 17-01-2019

并且您调用了 the_sub_field() 而您必须使用 get_sub_field() 因为您想要 检索 值并且 不显示它直接。