PHP Function Reference

PHP idate() Function



The PHP idate() function returns a number formatted according to the specified format string using the given integer timestamp or the current local time if no timestamp is provided.

Note: Unlike the function date(), idate() accepts just one char in the format parameter.

Syntax

idate(format, timestamp)

Parameters

format Required. Specify how to return the result. One of the following characters is allowed:
  • B - Swatch Beat/Internet Time
  • d - Day of the month
  • h - Hour (12 hour format)
  • H - Hour (24 hour format)
  • i - Minutes
  • I (uppercase i) - returns 1 if DST is activated, 0 otherwise
  • L (uppercase 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 UTC
  • w - Day of the week (0 on Sunday)
  • W - ISO-8601 week number of year, weeks starting on Monday
  • y - Year (1 or 2 digits)
  • Y - Year (4 digits)
  • z - Day of the year
  • Z - Timezone offset in seconds
timestamp Optional. Specify a Unix timestamp representing the date. If it is omitted or null, it defaults to the current local time.

Return Value

Returns an int on success, or false on failure. As this function always returns an int and as it can't start with a "0". Therefore, it may return fewer digits than expected.

Exceptions

Throws a E_WARNING if the time zone is not valid.

Example: idate() example

The example below shows the usage of idate() function. In this example current local time is used.

<?php
echo "B: ".idate("B")."\n";
echo "d: ".idate("d")."\n";
echo "h: ".idate("h")."\n";
echo "H: ".idate("H")."\n";
echo "i: ".idate("i")."\n";
echo "I: ".idate("I")."\n";
echo "L: ".idate("L")."\n";
echo "m: ".idate("m")."\n";
echo "s: ".idate("s")."\n";
echo "t: ".idate("t")."\n";
echo "U: ".idate("U")."\n";
echo "w: ".idate("w")."\n";
echo "W: ".idate("W")."\n";
echo "y: ".idate("y")."\n";
echo "Y: ".idate("Y")."\n";
echo "z: ".idate("z")."\n";
echo "Z: ".idate("Z")."\n";
?>

The output of the above code will be:

B: 762
d: 15
h: 5
H: 17
i: 17
I: 0
L: 0
m: 9
s: 54
t: 30
U: 1631726274
w: 3
W: 37
y: 21
Y: 2021
z: 257
Z: 0

Example: using timestamp parameter

Consider the example below where a timestamp is provided with this function.

<?php
//creating a timestamp
$timestamp = strtotime('15-May-2015 10:25:48');  

echo "B: ".idate("B", $timestamp)."\n";
echo "d: ".idate("d", $timestamp)."\n";
echo "h: ".idate("h", $timestamp)."\n";
echo "H: ".idate("H", $timestamp)."\n";
echo "i: ".idate("i", $timestamp)."\n";
echo "I: ".idate("I", $timestamp)."\n";
echo "L: ".idate("L", $timestamp)."\n";
echo "m: ".idate("m", $timestamp)."\n";
echo "s: ".idate("s", $timestamp)."\n";
echo "t: ".idate("t", $timestamp)."\n";
echo "U: ".idate("U", $timestamp)."\n";
echo "w: ".idate("w", $timestamp)."\n";
echo "W: ".idate("W", $timestamp)."\n";
echo "y: ".idate("y", $timestamp)."\n";
echo "Y: ".idate("Y", $timestamp)."\n";
echo "z: ".idate("z", $timestamp)."\n";
echo "Z: ".idate("Z", $timestamp)."\n";
?>

The output of the above code will be:

B: 476
d: 15
h: 10
H: 10
i: 25
I: 0
L: 0
m: 5
s: 48
t: 31
U: 1431685548
w: 5
W: 20
y: 15
Y: 2015
z: 134
Z: 0

❮ PHP Date and Time Reference