PHP date_interval_format()/DateInterval::format() Function

# PHP date_interval_format() Function

PHP Date/Time Reference

## Example

Calculate the interval between two dates, then format the interval:

<?php
$date1=date_create("2013-01-01");
$date2=date_create("2013-02-10");
$diff=date_diff($date1,$date2);
// %a outputs the total number of days
echo $diff->format("Total number of days: %a.");
?>
Run example »

## Definition and Usage

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

The DateInterval::format() function is used to format the interval.

## Syntax

DateInterval::format(format);

Parameter | Description
--- | ---

format

Required. Specifies the format. The following characters can be used in the format parameter string:

- % - 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)
- R - Sign "-" when negative, "+" when positive
- r - Sign "-" when negative, empty when positive

Note: Each format character must be prefixed by a % sign!

## Technical Details

Return Value: | Returns the formatted interval
PHP Version: | 5.3+

PHP Date/Time Reference

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples