Open In App

PHP | idate() Function

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.

Syntax:



int idate( $format, $timestamp )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: It returns an integer value according to the specified format using the given timestamp.



Exceptions:

Below programs illustrate the idate() function in PHP:

Program 1:




<?php
  
// 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>";
?>

Output:
2018
11
22
238

Program 2:




<?php
  
// Parsing English textual datetime description into a Unix timestamp
$timestamp = strtotime('24th August 2018'); 
  
// Formatting local date/time as Year
echo idate('Y', $timestamp);
?>

Output:
2018

Related Articles:

Reference: http://php.net/manual/en/function.idate.php


Article Tags :