PHP | idate() Function

The idate() function is an inbuilt function in PHP which is used to format a local time/date as an integer. The $format and $timestamp are sent as parameters to the idate() function and it returns an integer formatted according to the specified format using the given timestamp. Unlike the function date(), idate() accepts just one char in the format parameter.


int idate( $format, $timestamp )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $format: It is a mandatory parameter which specifies the format of the result. The format parameter can have the following values:
    • B – Swatch Beat/Internet Time
    • d – Day of the month
    • h – Hour (12 hour format)
    • H – Hour (24 hour format)
    • i – Minutes
    • I – returns 1 if DST (daylight saving time) is activated, 0 otherwise
    • L – returns 1 for leap year, 0 otherwise
    • m – Month number
    • s – Seconds
    • t – Days in current month
    • U – Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
    • w – Day of the week (Sunday=0)
    • W – ISO-8601 week number of year (week starts on Monday)
    • y – Year (1 or 2 digits)
    • Y – Year (4 digits)
    • z – Day of the year
    • Z – Timezone offset in seconds
  • $timestamp: It is an optional parameter which specifies a Unix timestamp that represents the date/time to be formatted.

Return Value: It returns an integer value according to the specified format using the given timestamp.


  • The idate() function throws a E_NOTICE on every call to a date/time if the time zone is not valid.
  • The idate() function throws a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable.

Below programs illustrate the idate() function in PHP:

Program 1:

// Formatting local date/time as Year
echo idate("Y") . "<br>";
// Formatting local date/time as Hour(24 hr format)
echo idate("H") . "<br>";
// Formatting local date/time as Minutes
echo idate("i") . "<br>";
// Formatting local date/time as day of the year 
echo idate("z") . "<br>";



Program 2:

// Parsing English textual datetime description into a Unix timestamp
$timestamp = strtotime('24th August 2018'); 
// Formatting local date/time as Year
echo idate('Y', $timestamp);



Related Articles:

Reference: http://php.net/manual/en/function.idate.php

This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment



load comments

Subscribe to Our Newsletter