Home >>PHP Date Time Functions >PHP idate() Function
PHP idate() function is used to format a local time/date as an integer. It accepts two parameters $format and $timestamp. It returns an integer formatted according to the specified format using the given timestamp.
Syntax:
idate(format, timestamp);
Parameter | Description |
---|---|
format | This is a required parameter. This parameter defines how to return the result. |
timestamp | This is an optional parameter. This parameter defines a Unix timestamp that represents the date and/or time to be formatted. |
Here is an example of idate() function in PHP:
<html> <body> <?php echo "Date: ".idate("d")."<br>"; echo "Hour: ".idate("h")."<br>"; echo "Hour: ".idate("H")."<br>"; echo "Minutes: ".idate("i")."<br>"; echo "Month: ".idate("m")."<br>"; echo "second: ".idate("s")."<br>"; echo "Days in current month: ".idate("t")."<br>"; echo "Day of the week: ".idate("w")."<br>"; echo "week of the year: ".idate("W")."<br>"; echo "Last 2 digit of year: ".idate("y")."<br>"; echo "Year: ".idate("Y")."<br>"; echo "Days of the year: ".idate("z")."<br>"; ?> </body> </html>
Example 2:
<html> <body> <?php echo "Date: ".idate("d",1581669933)."<br>"; echo "Hour: ".idate("h",1581669933)."<br>"; echo "Hour: ".idate("H",1581669933)."<br>"; echo "Minutes: ".idate("i",1581669933)."<br>"; echo "Month: ".idate("m",1581669933)."<br>"; echo "second: ".idate("s",1581669933)."<br>"; echo "Days in current month: ".idate("t",1581669933)."<br>"; echo "Day of the week: ".idate("w",1581669933)."<br>"; echo "week of the year: ".idate("W",1581669933)."<br>"; echo "Last 2 digit of year: ".idate("y",1581669933)."<br>"; echo "Year: ".idate("Y",1581669933)."<br>"; echo "Days of the year: ".idate("z",1581669933)."<br>"; ?> </body> </html>