Open In App

PHP | idate() Function

Last Updated : 27 Aug, 2018
Like Article

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:


Similar Reads

How to get the function name inside a function in PHP ?
To get the function name inside the PHP function we need to use Magic constants(__FUNCTION__). Magic constants: Magic constants are the predefined constants in PHP which is used on the basis of their use. These constants are starts and end with a double underscore (__). These constants are created by various extensions. Syntax: $string = __FUNCTION
1 min read
How the User-Defined Function differs from Built-in Function in PHP ?
In PHP, functions are blocks of reusable code that perform specific tasks. They enhance code readability, modularity, and maintainability by encapsulating logic into named units. PHP functions can be categorized into two main types: user-defined functions and built-in functions. User-Defined FunctionsUser-defined functions are functions created by
2 min read
PHP 5 vs PHP 7
PHP is a server side scripting language designed for web development by Rasmus Lerdorf in 1994. Since its launch in 1994 PHP has become an industry standard supporting almost 80% of the websites ( 79.8% to be precise) with its closest competitor being ASP.Net at 19.8% and others like Ruby, Java trailing far behind. The PHP development team released
4 min read
PHP | Get PHP configuration information using phpinfo()
PHP provides us with a built-in function phpinfo() which gives us the details about the PHP version and PHP configuration of PHP installed in our system. To know about the Configurations and PHP version which is installed in your computer, a simple PHP script can be used. The script consists of a PHP function called "phpinfo()" which outputs inform
2 min read
PHP | php.ini File Configuration
At the time of PHP installation, php.ini is a special file provided as a default configuration file. It's very essential configuration file which controls, what a user can or cannot do with the website. Each time PHP is initialized, the php.ini file is read by the system. Sometimes you need to change the behavior of PHP at runtime, then this config
5 min read
How to import config.php file in a PHP script ?
The include statement in PHP copies the code of text from the file mentioned, into the file that uses the include statement. It directs the preprocessor to insert the content specified into the following program. The name of the file to be included is written in double-quotes. It is a good practice to write the basic database details and user detai
2 min read
How to include content of a PHP file into another PHP file ?
Including the content of a PHP file into another file reduces the complexity of code by reducing the code and improving its modularity by splitting the code into different files so that it is easy to understand and manage. There are two ways to do it by using the following PHP functions. PHP include() Function: It will show the warning if the file
2 min read
PHP | imagecreatetruecolor() Function
The imagecreatetruecolor() function is an inbuilt function in PHP which is used to create a new true-color image. This function returns a blank image of the given size. Syntax: resource imagecreatetruecolor( $width, $height ) Parameters: This function accepts two parameters as mentioned above and described below: $width: This parameter is used to s
2 min read
PHP fpassthru( ) Function
The fpassthru() function in PHP is an inbuilt function which is used to read data from a current position from a specified file until end of file and then write the result to the output buffer. The file which has to be read is sent as a parameter to the fpassthru() function and it returns the number of characters passed on success or FALSE on failu
2 min read
PHP | ImagickDraw getTextAlignment() Function
The ImagickDraw::getTextAlignment() function is an inbuilt function in PHP which is used to get the alignment applied when annotating with text. It helps to format the text by making it stick to left, right or middle. Syntax: int ImagickDraw::getTextAlignment( void ) Parameters: This function doesn’t accept any parameter. Return Value: This functio
2 min read