Support

Account

Home Forums ACF PRO Count date picker days

Solved

Count date picker days

  • Hi,

    I have two fields with an date picker.

    date from – to ( <?php the_field('retreat_date_from'); ?> - <?php the_field('retreat_date_to') ?>)
    so will will display the count days. in this case 7 days. How can I display the days?

    thanks

    kind regards
    wolfie

  • Are you trying to get the number of days between the two dates?
    if so:

    $date_1 = date_create(get_field('retreat_date_from'));
    $date_2 = date_create(get_field('retreat_date_to'));
    $diff = date_diff($date_1,$date_2);

    This will show you the output:

    echo "<pre>";
    echo $diff->days;
    echo "</pre>";
  • hi bosoxbill,

    I solved this 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;
    ?>
  • hi,
    i have one issue.
    i can’t count the difference in October. other months works

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Count date picker days’ is closed to new replies.