English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP idate() Function Usage and Example

PHP Date & Time Function Manual

The idate() function formats the local time and date into an integer

Definition and Usage

The idate() function accepts a format string as a parameter to format the local date in the specified format/Time, then return the date/Time

Syntax

idate($format, [$timestamp])

Format the timestamp according to the given format character and return the numeric result.

timestamp is optional, the default value is the local current time, that is, the value of time(). Unlike date(), idate() only accepts a single character as the format parameter.

The format parameter can recognize the following characters
format characterDescription
BSwatch Beat/Internet Time
dDay of the month
hHour (12 Hour format)
HHour (24 Hour format)
iMinutes
IIf daylight saving time is enabled, then returns 1, otherwise returns 0
LIf it is a leap year, then returns 1, otherwise returns 0
mMonth number
sSeconds
tTotal number of days in the month
UThe Unix epoch (January 1 197The number of seconds since 0 00:00:00 GMT - this is the same as time() The same as
wDay of the week (Sunday is 0)
WISO-8601 The week number in the year, starting from Monday
yYear (1 or 2 digits - see below for details)
YYear (4 digits)
zDay of the year in the year
ZTime zone offset in seconds

Parameter

Serial NumberParameters and Description
1

format (required)

This is a string value representing the local date you need to format/Time Format

2

timestamp (optional)

This is an integer representing the timestamp of the current local time.

Return Value

The PHP idate() function returns an integer value representing a formatted date/Time

PHP Version

This function was originally in PHP 5introduced in version 0 and can be used in all higher versions.

Online Example

The following examples demonstrateidate()Function Usage-

<?php
   $format = "U";
   $res = idate($format);
   print("Timestamp: " . $res);
?>
Test to see‹/›

Output Result

Timestamp: 1589280496

Online Example

The following examples call the function by passing the timestamp parameteridate()Function-

<?php
   $date = date_create();
   $timestamp = date_timestamp_get($date);
   $format = "U";
   $res = idate($format, $timestamp);
   print("Timestamp: " . $res);
?>
Test to see‹/›

Output Result

Timestamp: 1589282148

Online Example

Let's seeidate()Various format characters of the function and their results-

<?php
   print("B :".idate("B"));
   print("\n");
   print("d :".idate("d"));
   print("\n");
   print("h :".idate("h"));
   print("\n");
   print("H: " . idate("H"));
   print("\n");
   print("i :".idate("i"));
   print("\n"); 
   print("I :".idate("I"));
   print("\n");
   print("L :".idate("L"));
   print("\n");
   print("m :".idate("m"));
   print("\n");
   print("s :".idate("s"));
   print("\n");
   print("t :".idate("t"));
   print("\n");
   print("U :".idate("U"));
   print("\n");
   print("w :".idate("w"));
   print("\n");
   print("w:".idate("W"));
   print("\n");
   print("y :".idate("y"));
   print("\n");
   print("Y :".idate("Y"));
   print("\n");
   print("z :".idate("z"));
   print("\n");
   print("Z :".idate("Z"));
   print("\n");
?>
Test to see‹/›

This will produce the following output-

B :758
d :18
h :5
H: 17
i :11
I :0
L :1
m :5
s :54
t :31
U :1589821914
w :1
w:21
y :20
Y :2020
z :138
Z :0

Online Example

<?php
   $timestamp = strtotime('1st January 2014);   
   echo idate('y', $timestamp);
   echo"\n";
   echo idate('t', $timestamp);
?>
Test to see‹/›

This will produce the following output-

14
31