Follow us on Facebook
Faucibus toroot menuts
Date And Time
Date is one of the frequently used things in any web applications. Whether you want to keep record of the order date or you want to know which date did you book your hotel last time, you need date function for date manipulation.
PHP provides function called date() which converts machine timestamp date into human readable format.
The reason we require date function is that the computer stores dates and times in a format called UNIX Timestamp, which calculates time as number of seconds since the beginning of the Unix epoch which starts from midnight Greenwich Mean Time on January 1, 1970 i.e. January 1, 1970 00:00:00 GMT .
Since reading this format is not possible for human being, PHP converts a timestamp to a format which is human readable format.
The first argument is the date format and the second argument is optional timestamp. If not provided then current data and time is taken.
The required format parameter of the date() function specifies how to format the date (or time).
There are several date formats which you can find in PHP’s official website www. php.net/manual/en/function.date.php . Below are few of the common date functions.
d – Shows the day of the date (01 to 31)
m –Shows the month of the date (01 to 12)
Y – Shows the year (in four digits)
l (lowercase 'L') - Represents the day of the week
If the server location is at different country/place then it’s possible that you may not get correct time because of being in different time-zone. If you want to get/display correct time zone as per the location, then you can set time-zone and it will display correct time.
For example, if you want to display correct time of Kolkata, then you need to write 'Asia/Kolkata'.
h – Displays hour in 12-hour format with leading zeros (01 to 12).
H – Displays hour in in 24-hour format with leading zeros (00 to 23).
i – Displays minutes with leading zeros (00 to 59).
s – Displays seconds with leading zeros (00 to 59).
a – Displays lowercase ante meridian and post meridian (am or pm).
A – Displays uppercase ante meridian and post meridian (AM or PM).
The mktime() function is used to create the timestamp for a specific date and time.
If no date and time is provided, the timestamp for the current date and time is returned.
mktime(hour, minute, second, month, day, year)
In the above example, first parameter is second, next minute then hour, then month and data and then year.