Home >>PHP Date Time Functions >PHP idate() Function

PHP idate() Function

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 Values

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>
Output:
Date: 1
Hour: 10
Hour: 10
Minutes: 46
Month: 2
second: 39
Days in current month: 29
Day of the week: 6
week of the year: 5
Last 2 digit of year: 20
Year: 2020
Days of the year: 31

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>
Output:
Date: 14
Hour: 8
Hour: 8
Minutes: 45
Month: 2
second: 33
Days in current month: 29
Day of the week: 5
week of the year: 7
Last 2 digit of year: 20
Year: 2020
Days of the year: 44

No Sidebar ads