The PHP date() function formats a timestamp to a more readable date and time.
* Timestamp is a sequence of characters, denoting the date and/or time at which a certain event occured.
Syntax:
date(format,timestamp)
PHP Date() – Format the Date
The required format parameter in the date() function specifies how to format the date/time.
Here are some characters that can be used:
* d – Represents the day of the month (01 to 31)
* m – Represents a month (01 to 12)
* Y – Represents a year (in four digits)
PHP Date() – Adding a Timestamp
Syntax for mktime()
mktime(hour,minute,second,month,day,year,is_dst)
<?php
echo date(“Y-m-d”).”<br/>”;
$tomorrow=mktime(0,0,0,date(“m”),date(“d”)+1,date(“Y”));
echo “tomorrow is “.date(“Y-m-d”,$tomorrow).”<br/>”;
$yesterday=mktime(0,0,0,date(“m”),date(“d”)-1,date(“Y”));
echo “yesterday is “.date(“Y-m-d”,$yesterday).”<br/>”;
?>
Output:
2011-04-25
tomorrow is 2011-04-26
yesterday is 2011-04-24
Recent Comments