Support

Account

Home Forums General Issues Calculate Number of Years Between Two Date Pickers

Unread

Calculate Number of Years Between Two Date Pickers

  • I have seen examples that show the number of years between a date picker and the current date but I am using a date of birth and date of passing to calculate the age of the person when they passed away.

    Any ideas how this can be achieved?

    Could I modify the below?

    
    <?php
    if(get_field('date_of_birth')) {
    $date = get_field('date_of_birth');
    $birthday = new DateTime($date);
    $interval = $birthday->diff(new DateTime);
    ?>
    <p>Age: <strong><?php echo $interval->y; ?></strong></p>
    <?php } ?>
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.