The Date is an inbuilt function used to format the timestamp. The computer stores date and time in UNIX Timestamp. This time is measured as a number of seconds since Jan 1, 1970. Since this is impractical for humans to read, PHP converts timestamp to a format that is readable and more understandable to humans.
date( format, timestamp )
- The format parameter in the date() function specifies the format of returned date and time.
- The timestamp is an optional parameter. If it is not included then the current date and time will be used.
In order to get the current year as four digits, Y is used as a parameter to date() function as shown in the below:
Current Year is :2019
Format options available in date() function: The format parameter of the date() function is a string that can contain multiple characters allowing to generate dates in various formats are listed below:
- d – Represents the day of the month. It uses two digits with leading zeros (01 or 31).
- D – Represents day of the week in the text (Mon to Sun).
- m – Represents month in numbers with leading zeros (01 or 12).
- M – Represents month in text, abbreviated (Jan to Dec).
- y – Represents year in two digits (08 or 14).
- Y – Represents year in four digits (2008 or 2014).
- How to get the current weeknumber of the year?
- How to get current function name in PHP?
- How to get the size of screen, current web page and browser window using jQuery?
- Get the current URL using jQuery?
- How to get the current date and time in seconds?
- How to Get the Current Working Directory in Golang?
- How to get the path of current script using Node.js ?
- How to get title of current HTML page using jQuery ?
- How to Get Current time in Golang?
- How to Get Current Weekday in Golang?
- How to Get Current Date and Time in Various Format in Golang?
- Get current timestamp using Python
- How to get the current URL using AngularJS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.