The PHP Date() Function
The PHP date() function convert a timestamp to a more readable date and time.
The computer stores dates and times in a format called UNIX Timestamp, which measures time as a number of seconds since the beginning of the Unix epoch (midnight Greenwich Mean Time on January 1, 1970 i.e. January 1, 1970 00:00:00 GMT ).
Since this is an impractical format for humans to read, PHP converts a timestamp to a format that is readable to humans and dates from your notation into a timestamp the computer understands. The syntax of the PHP date() function can be given with.
Date(format, timestamp)
Formatting the Dates and Times with PHP
The format parameter of the date() function is in fact a string that can contain multiple characters allowing you to generate a date string containing various components of the date and time, like day of the week, AM or PM, etc. Here are some the date-related formatting characters that are commonly used in format string:
• d – Represent day of the month; two digits with leading zeros (01 or 31)
• D – Represent day of the week in text as an abbreviation (Mon to Sun)
• m – Represent month in numbers with leading zeros (01 or 12)
• M – Represent month in text, abbreviated (Jan to Dec)
• y – Represent year in two digits (08 or 14)
• Y – Represent year in four digits (2008 or 2014)
The parts of the date can be separated by inserting other characters, like hyphens (-), dots (.), slashes (/), or spaces to add additional visual formatting.
"; echo date("d-m-Y") . "
"; echo date("d.m.Y"); ?>
Similarly you can use the following characters to format the time string:
• h – Represent hour in 12-hour format with leading zeros (01 to 12)
• H – Represent hour in in 24-hour format with leading zeros (00 to 23)
• i – Represent minutes with leading zeros (00 to 59)
• s – Represent seconds with leading zeros (00 to 59)
• a – Represent lowercase ante meridiem and post meridiem (am or pm)
• A – Represent uppercase Ante meridiem and Post meridiem (AM or PM)
The PHP code in the following example displays the date in different formats:
"; echo date("F d, Y h:i:s A") . "
"; echo date("h:i a"); ?>
Nice one, Thanks
Have you ever thought about creating an e-book or guest authoring
on other websites? I have a blog based on the same topics you discuss and would love to have you
share some stories/information. I know my readers would appreciate your work.
If you are even remotely interested, feel free to send me an e mail.
It’s an amazing paragraph designed forr ɑll the internet visitors; tһey will
take bednefit fгom it I am sure.
I like what you guys are up also. Such intelligent work and reporting!
Keep up the excellent works guys I have incorporated you guys to my blogroll.
I think it will improve the value of my site :
).
Hello colleagues, pleasant paragraph and good urging commented here,
I am truly enjoying by these.
Terrific work! That is the kind of info that are supposed to
be shared around the net. Shame on Google for not positioning this submit upper!
Come on over and visit my website . Thank you =)