Easy Tutorial
❮ Php Curl Func Array Each ❯

PHP date_interval_format() Function

PHP Date/Time Reference Manual

Calculate the interval between two dates and then format the time interval:

Example

<?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 between two dates
echo $diff->format("Total days between dates: %a days.");
?>

Definition and Usage

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

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

Syntax

Parameter Description
format Required. Specifies the format. The format parameter string can use the following characters: % - Literal %<br> Y - Year, at least 2 digits, with leading zero (e.g., 03)<br> y - Year (e.g., 3)<br> M - Month, with leading zero (e.g., 06)<br> m - Month (e.g., 6)<br> D - Day, with leading zero (e.g., 09)<br> d - Day (e.g., 9)<br> a - Total number of days as a result of date_diff()<br> H - Hour, with leading zero (e.g., 08, 23)<br> h - Hour (e.g., 8, 23)<br> I - Minute, with leading zero (e.g., 08, 23)<br> i - Minute (e.g., 8, 23)<br> S - Second, with leading zero (e.g., 08, 23)<br> s - Second (e.g., 8, 23)<br> R - Sign "-" when negative, "+" when positive<br> r - Sign "-" when negative, empty when positive Note: Each format string must be prefixed with a % character!

Technical Details

Return Value: Returns the formatted time interval.
PHP Version: 5.3+
--- ---
❮ Php Curl Func Array Each ❯