logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Low Carb: 8:00 PM

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

The PHP Date Function

Guest Author - Diane Cipollo

The PHP date() function is one of the most useful built-in functions. There are many uses for the PHP built-in date() function. You can use it to simply collect and display the current date and time on you webpages. On the other hand, you can use the date() function as a timestamp for numerous purposes in your PHP programs.

Basically what the date() function does is to return the current date and time using a set of parameters that you control. Click here for a chart that summarizes the controls you will use to format the date() function. Let's take a look at the basic syntax for the PHP data() function.

Basic PHP Code
date(format, [timestamp]);

Example
echo date("g:ia l - F d, Y");


As you can see, the function begins with the function name, date. Inside the parenthesis are the "format controls" and the [optional timestamp] separated by a comma. The whole thing ends with a semicolon.

Optional Timestamp
You might want to supply a special timestamp such as a past date. If a timestamp is not supplied, the current date and time of the server is used by default.

g:ia l - F d, Y
Format
The format is the parameters that you can set to control the way the current date and time is formatted and displayed. In our example, we have formatted the time of day to be displayed as the following when the webpage is viewed on the start of New Years Day 2005.

12:00am Saturday - January 1, 2005

hours : minutes am/pm (12:00am)
day of the week in text (Saturday) syntax is lowercase "L"
hyphen
the month in text (January)
day of the month in digits (1)
comma
the year in digits (2005)

All of this will be displayed in the web browser using the echo statement. You will notice that I have added the punctuation to the string that I want printed to the web browser. I have added a space hyphen space ( - ) between the day of the week and the month. I have also added a comma after January 1. Finally, I have added the colon between hour and minutes. (Remember to escape any special characters that you might add to your datetime string.) When using an echo statement your string must be between quotation marks ("string to be printed to web brower").

The PHP Date Function Format Chart




This site needs an editor - click to learn more!

Add The+PHP+Date+Function to Twitter Add The+PHP+Date+Function to Facebook Add The+PHP+Date+Function to MySpace Add The+PHP+Date+Function to Del.icio.us Digg The+PHP+Date+Function Add The+PHP+Date+Function to Yahoo My Web Add The+PHP+Date+Function to Google Bookmarks Add The+PHP+Date+Function to Stumbleupon Add The+PHP+Date+Function to Reddit




RSS | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor