PHP Reference

Quick Reference

The PHP date_interval_format() function is an alias of DateInterval::format().

<?php
$date1 = date_create('2013-01-11');
$date2 = date_create('2023-01-11');
$diff = date_diff($date1, $date2);

echo $diff->format('Total number of days: %a');
?>

Output

Total number of days: 3652

Syntax

DateInterval::format(format)

Parameters

ParameterDescription
formatSpecifies the format for the date; Each format character must be prefixed by a % sign (required):

    % - Literal %
    Y - Year, at least 2 digits with leading zero (e.g 03)
    y - Year (e.g 3)
    M - Month, with leading zero (e.g 06)
    m - Month (e.g 6)
    D - Day, with leading zero (e.g 09)
    d - Day (e.g 9)
    a - Total number of days as a result of date_diff()
    H - Hours, with leading zero (e.g 08, 23)
    h - Hours (e.g 8, 23)
    I - Minutes, with leading zero (e.g 08, 23)
    i - Minutes (e.g 8, 23)
    S - Seconds, with leading zero (e.g 08, 23)
    s - Seconds (e.g 8, 23)
    F - Microseconds, at least 6 digits (e.g 004403, 235689)
    f - Microseconds (e.g 4403, 235689)
    R - Sign "-" when negative, "+" when positive
    r - Sign "-" when negative, empty when positive

PHP Notes:

  • When using PHP, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
  • Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.