PHP
HTML
CSS
JavaScript
jQuery
SQL
WordPress
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)
				
			

Parameter

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

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.

PHP
HTML
CSS
JavaScript
jQuery
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.