I want to display the days remaining till the date specified in a custom field inside of wordpress. My custom field is named bewerbungs_frist
. I'M using this code:
<?php $days = ceil((strtotime("<?php the_field('bewerbungsfrist'); ?>") - time())/(60*60*24));
$s='';
if ($days!=1) {
$s='s';
}
echo $days. " days "; ?>
As a output I get something like -1500 days. That can't be right. Can somebody help me out?
I solved the issue with this code:
<p>Bewerbungsfrist: <?php $date = DateTime::createFromFormat('Ymd', get_field('bewerbungs_frist')); echo $date->format('d.m.Y');?></p>
noch <?php $days = ceil((strtotime(get_field('bewerbungs_frist')) - time())/(60*60*24));
echo $days. " Tage "; ?>
You are opening wrong php tags between already opened tags
try this
$days = ceil((strtotime(the_field('bewerbungsfrist')) - time())/(60*60*24));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.