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 character | Description |
B | Swatch Beat/Internet Time |
d | Day of the month (1-31) |
h | Hour (12 hour format, 1-12) |
H | Hour (24 hour format, 0-23) |
i | Minutes (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 |
m | Month number (1-12) |
N | ISO-8601 day of the week (1 for Monday through 7 for Sunday) |
o | ISO-8601 year (4 digits) |
s | Seconds (0-59) |
t | Days in current month (28-31) |
U | Seconds since the Unix Epoch – January 1 1970 00:00:00 UTC ( same as PHP time() Function ) |
w | Day of the week (0 = Sunday, 6 = Saturday) |
W | ISO-8601 week number of year, weeks starting on Monday |
Y | Year (1 or 2 digits – check note below) |
Y | Year (4 digits) |
z | Day of the year (0-365) |
Z | Timezone 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.