Syntax:date (format, timestamp)
Explanation : - The format parameter to the date() function specifies the format of the date and time returned.
- The time stamp is optional. If not enabled, the current date and time will be used.
To get the current year as four digits, Y is used as a parameter to date(), as shown below:
Program :
// PHP program for getting
// current year
echo
"Current Year is:"
;
// Save the year
// variable
$year
=
date
(
"Y"
);
// Display year
echo
$year
;
?>
Exit:Current Year is : 2019
formatting parameters available in the date() function:the formatting parameter of the date() function is a string that can contain several characters, allowing to generate dates in different formats, are listed below: - d - represents the day of the month. Two digits with leading zeros (01 or 31) are used.
- D - represents the day of the week in text (Monday through Sunday).
- m - represents the month in numbers with leading zeros (01 or 12).
- M - represents the month in text, abbreviated (January to December).
- y - represents the year in two digits (08 or 14).
- Y - represents the year in four digits (2008 or 2014).