PHP idate() Function

What is PHP idate() Function?

If you want to extract just one specific date/time related integer data from a timestamp or from the current local timestamp, use PHP idate() function. The “i” in “idata() function” stands for “integer”.

Syntax:

idate(format, timestamp)

Parameters:

The Function has 1 required parameter and 1 optional parameter-

format (Required): It specifies a single character that determines what value you want to get as an integer.

You can use the following characters as format parameter –

format characterDescription
BSwatch Beat/Internet Time
dDay of the month (1-31)
hHour (12 hour format, 1-12)
HHour (24 hour format, 0-23)
iMinutes (0-59)
I (uppercase i)returns 1 if DST (Daylight Saving Time) is activated, 0 otherwise
L (uppercase l)returns 1 for leap year, 0 otherwise
mMonth number (1-12)
NISO-8601 day of the week (1 for Monday through 7 for Sunday)
oISO-8601 year (4 digits)
sSeconds (0-59)
tDays in current month (28-31)
USeconds since the Unix Epoch – January 1 1970 00:00:00 UTC ( same as PHP time() Function )
wDay of the week (0 = Sunday, 6 = Saturday)
WISO-8601 week number of year, weeks starting on Monday
YYear (1 or 2 digits – check note below)
YYear (4 digits)
zDay of the year (0-365)
ZTimezone offset in seconds (-43200 to 43200)

timestamp (Optional): it specifies a timestamp that you provide. If omitted the parameter, the function uses the current local time which you can also get from time() function.

Return Values:

The function returns-

  • An integer – on success
  • FALSE – on failure

Examples:

Example 1:

<?php
date_default_timezone_set('America/Los_Angeles');

echo "Current Day of the month: " . idate("d") . ", ";
echo " Hour: " . idate("H") . ", ";
echo " Minute: " . idate("i") . "<br>";
?>

Output:

Current Day of the month: 11, Hour: 19, Minute: 34

Example 2:

<?php
echo "Current month: " . idate("m");
?>

Output:

Current month: 1

Notes on idate() Function:

  • As the function returns integer, it omits any 0 starting in the beginning. Example, it returns “5”, not “05”. See example below-
  • idate()  function always take just one character as a format parameter, on the other hand, date() function can accept multiple characters.
    <?php
    echo "Current month using idate() function: " . idate("m") . "<br />";
    echo "Current date using date() function: " . date("m-d-Y");
    ?>
    

    Output:

    Current month using idate() function: 1
    Current date using date() function: 01-11-2026

PHP Version Support:

PHP 5, PHP 7, PHP 8

Summary: PHP idate() Function

The idate() function is one of the built-in PHP date and time function. Use this function when you need date/time information as an integer.

Reference:

https://www.php.net/manual/en/function.idate.php