I'm trying to calculate the difference in days between two post custom field values that have been inputted via a front end date picker (gravity forms).
A simplified version of what I have to get my two dates is below:
<?php $date1 = get_field('date_start', false, false); $date1 = new DateTime($date1); ?> <p><?php echo $date1->format('j M'); ?></p> <?php $date2 = get_field('date_fin', false, false); $date2 = new DateTime($date2); ?> <p><?php echo $date2->format('j M'); ?></p>
I need to calculate and output the day difference between the above outputted dates.
Say if I had an output like:
I would like to be able to create a variable or some type of php output that would say:
'7 days late'
Then to make things even more complicated if the difference is zero I would like to say: