hi,
i have an issue to count the difference in the october month.
<?php $date_from = get_field( 'retreat_date_from' );
$date_to = get_field( 'retreat_date_to' );
$date_1 = new DateTime(date('Y-m-d', strtotime($date_from)));
$date_2 = new DateTime(date('Y-m-d', strtotime($date_to)));
$days = $date_1->diff($date_2)->days;
?>
HTML
<a href="<?php echo the_permalink(); ?>"><h3 class="uk-card-title uk-margin-remove-bottom"><?php echo $days; ?> Tage <?php the_title(); ?></h3></a>
the october date returns 0 Tage and 1970-01-01
var_dump($days, $date_from, $date_to, $date_1, $date_2);
returns:
int(0) string(10) “10 Oktober” string(15) “14 Oktober 2018” object(DateTime)#4743 (3) { [“date”]=> string(26) “1970-01-01 00:00:00.000000” [“timezone_type”]=> int(3) [“timezone”]=> string(3) “UTC” } object(DateTime)#4744 (3) { [“date”]=> string(26) “1970-01-01 00:00:00.000000” [“timezone_type”]=> int(3) [“timezone”]=> string(3) “UTC” }
maybe someone can help me
kind regards
strtotime()
requires specific date formats and your fields are probably not returning the date in a format that can be used. http://php.net/manual/en/datetime.formats.date.php, looking at your return values of 10 Oktober
and 14 Oktober 2018
are in any of the correct formats.
Hi John,
thank you for your response. I have fixed this issue with ->
<?php
$date_from = get_field( 'retreat_date_from' );
$date_to = get_field( 'retreat_date_to' );
$date_1 = new DateTime(date('Y-m-d', strtotime($date_from)));
$date_2 = new DateTime(date('Y-m-d', strtotime($date_to)));
$days = $date_1->diff($date_2)->days + 1;
// var_dump($days, $date_from, $date_to, $date_1, $date_2);
// var_dump(strtotime(get_field('retreat_date_to')));
?>
<div class="uk-card-body uk-padding-small">
<span class="location-card"><?php the_field('retreat_location'); ?></span>
<a href="<?php echo the_permalink(); ?>"><h3 class="uk-card-title uk-margin-remove-bottom"><?php echo $days; ?> Tage <?php the_title(); ?></h3></a>
<p class="uk-margin-remove-top"><?php echo date_i18n('j F', strtotime($date_from)); ?> - <?php echo date_i18n('j F Y', strtotime($date_to)); ?></p>
</div>
The topic ‘ACF Datepicker issue’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.