Which PHP function can return the current date/time?
date(format, timestamp)
The date
function returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp
is optional and defaults to the value of time().
And the parameters are -
format - Required. Specifies the format of the timestamp
timestamp - (Optional) Specifies a timestamp. Default is the current date and time
The required format parameter of the date()
function specifies how to format the date (or time)
.
Here are some characters that are commonly used for dates:
Other characters, like "/", ".", or "-"
can also be inserted between the characters to add additional formatting.
The example below formats today's date in three different ways:
";
echo "Today is " . date("Y.m.d") . "
";
echo "Today is " . date("Y-m-d") . "
";
echo "Today is " . date("l");
?>