13 January 2016

How to find out the amount of between two dates. For an example how many days have passed since a defined date.

Source code viewer
  1. // Define start date, from which we want to start the count.
  2. $start_date = new DateTime("2016-01-14");
  3. // Current date, to do the difference calculation.
  4. $current = new DateTime(date('Y-m-d'));
  5.  
  6. // Calculate difference of the dates and show the difference in days.
  7. $days = (int) $current->diff($start_date)->format("%a");
  8.  
  9. // If the days are divisible by 4.
  10. if (!($days % 4)) {
  11. // ...
  12. }
Programming Language: PHP