PHP 5 Date and Time

The PHP Date() Function

The PHP date() function convert a timestamp to a date and time.

mysql database store dates and times in a format called UNIX Timestamp , that is very diffcult
to read by human

PHP Date function coverty UNIX Timestamp into human redable date and time format

PHP date function example

date(format, timestamp)

Format — format value Required. format specify the date human redable date format
timestamp — Optional. Specifies a timestamp. Default is the current date and time

How to display simple date


d – Represents the day of the month (01 to 31)
m – Represents a month (01 to 12)
Y – Represents a year (in four digits)

How to display Simple time

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)

Set Tome Zone and display time

php date_default_timezone_set function first set time zone and display date accordingly

how to display Copyright Year

PHP strtotime Function

PHP strtotime() function is used to convert a human readable string to a Unix time

PHP 5.2 onwards one can do it using Object Oriented and DateTime()

Leave a Reply

Your email address will not be published. Required fields are marked *