You don't need to have mastered PHP or any other programming language to make use of PHP date functions for pretty basic web development. However, you should have some familiarity with server-side scripting, extensible hypertext mark-up language (XHTML), and know how to generate XHTML using PHP. If you're comfortable with these tasks, you'll do just fine in adding a date to your site using the PHP date function.
Set the Correct Default Date Before You Begin
If you skip this step, you could end up indicating an incorrect date and time to your visitors. If you're not running PHP on your own machine, but rather using the installation on a remote server, you'll probably want to set the timezone for where you and the people who work with you on the site are. For example, if you live in Chicago, United States, you could use the PHP date_default_timezone_set(); function to which you would pass the string: America/Chicago. Be sure to enclose the string within quote marks ("America/Chicago") or your code won't work. I used the PHP date function to generate the dates and times for three regions for this article: Buenos Aires, Casablanca, Morocco, and the Tahitian Islands.
You can see in the screen shots included just how the code looks that is behind the visual display of these dates and times. I supplied the needed option (string) for each zone. For example, date_default_timezone_set(America/Buenos_Aires"); sets a default time zone for the region in which the South American city of Buenos Aires is located. That default had to be changed for each subsequent region, but this allows you to display multiple international time zones on your site.
PHP Date Function: Learn How to Format Display
There's more than one way to display dates and times. Days and months can be written out or they can be abbreviated. They can be represented by one or two digits and time can be based on the twelve or twenty-four hour format. The letters "am" can be in lowercase or capitalized, seconds can appear or be left out altogether. Fortunately, the PHP date function allows such flexibility if you make use of the options available. You might want to consult the official online manual for all of your options as well as a list of valid time zone strings. However, I've included some that you might want to use. These options are used when printing the date. For example: echo "
Today is " . date('F j, Y') . "
Time: " . date('g:i A') . "";.
Below is a list of some of the most widely used options for formatting:
1. j - displays day of the month as one or two digits
2. g - time in 12-hour format, one or two digits
3. i - displays the minutes
4. Y - displays the year as four digits
5. M - abbreviates the month
6. F - full name of month
7. A - displays the letters for morning and evening in lowercase (am/pm)
8. a - displays the letters for morning and evening in capitals (AM/PM)
Published by Ana Kirk
Ana Kirk is an emergency medical technician (EMT) and part-time web developer. She is also a back-up translator and author of study materials for a Christian ministry. View profile
Starting a Web Design BusinessThe web design business is ideally suited to starting as a home-based business on a shoestring budget. Here are some tips I have learned over a decade in the business.- Non-Negative Web Design and BrandingA tech writer shares his experiences working with web designers, and draws two conclusions. First, it is more important to avoid design missteps than to include "positive" design features. Second, designers must be op...
- Web Design Project LifecycleSeparating the web design process into digestible chunks can make the whole project bearable.
- Hiring a Web Designer Exposé Information for hiring a web designer.
- Careers with a Web Design DegreeA simple guide to options for those considering a career in web design.
- PHP and Web Hosting with Mac
- PHP String and Date Basics
- Network Intrusion Detection Systems
- Introduction to Web Design and Development 1
- Brochure, Business Card Design and Development
- Starting in the Web Design Industry
- Holiday Shopping for the Web Designer on Your Christmas List




