PHP Date and Time
The PHP date() function is used to format a date/time.
The PHP Date() Function
The PHP date() function formats a timestamp to a more readable date and time
date(format,timestamp)
Get a Date
The required format parameter specifies how to format the date/time.
- d - Represents the day of the month (01 to 31)
- m - Represents a month (01 to 12)
- Y - Represents a year (in four digits)
- l (lowercase 'L') - Represents the day of the week
Other characters, like"/", ".", or "-" can also be inserted between the characters to add additional formatting.
PHP Tip - Automatic Copyright Year
Use the date() function to automatically update the copyright year on your website:
Get a Time
Following characters that are commonly used for times:
- H - 24-hour format of an hour (00 to 23)
- h - 12-hour format of an hour with leading zeros (01 to 12)
- i - Minutes with leading zeros (00 to 59)
- s - Seconds with leading zeros (00 to 59)
- a - Lowercase Ante meridiem and Post meridiem (am or pm)
Get Your Time Zone
Create a Date With mktime()
The PHP mktime() function returns the Unix timestamp for a date.
mktime(hour, minute, second, month, day, year)
Create a Date From a String With strtotime()
The PHP strtotime() function is used to convert a human readable date string into a Unix timestamp.
strtotime(time, now)