PHP Date() Function
Page 1 of 2
TRANSLATE
Search w3schools.com
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...
Search
REFERENCES | EXAMPLES | FORUM | ABOUT
YOUR FREE WEBSITE Free Flash Website Free Website Builder Free Web Design
Complete Customer Care Multi-channel Self-service and Assisted-service. Modular. Web 2.0 www.fuze.com Free Online Advertising See What $75 of Google Ads Can Do For Your Business. Try It Now! www.Google.com/AdWords Ryan Associates Your premier provider of Geneva workflow solutions. www.rynassociates.com
PHP Basic
PHP HOME PHP Intro PHP Install PHP Syntax
PHP Date() Function
Previous
The PHP date() function is used to format a time and/or date.
WEB HOSTING Best Web Hosting
Next Chapter
PHP MySQL Hosting Best Hosting Coupons UK Reseller Hosting Cloud Hosting Top Web Hosting $3.98 Unlimited Hosting Premium Website Design WEB BUILDING Download XML Editor FREE Website BUILDER Free Website TemplatesFree CSS Templates
PHP Variables PHP String PHP Operators PHP If...Else PHP Switch PHP Arrays PHP While Loops PHP For Loops PHP Functions PHP Forms PHP $_GET PHP $_POST
The PHP Date() Function
The PHP date() function formats a timestamp to a more readable date and time. A timestamp is a sequence of characters, denoting the date and/or time at which a certain event occurred.
Syntax
date(format,timestamp)
PHP Advanced
PHP Date PHP Include PHP File PHP File Upload PHP Cookies PHP Sessions PHP E-mail PHP Secure E-mail PHP Error PHP Exception PHP Filter
Parameter format timestamp
Description Required. Specifies the format of the timestamp Optional. Specifies a timestamp. Default is the current date and time
Make Your Own Website W3SCHOOLS EXAMS Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP
PHP Date() - Format the Date
The required format parameter in the date() function specifies how to format the date/time. Here are some characters that can be used: d - Represents the day of the month (01 to 31) m - Represents a month (01 to 12) Y - Represents a year (in four digits) A list of all the characters that can be used in the format parameter, can be found in our PHP Date reference. Other characters, like"/", ".", or "-" can also be inserted between the letters to add additional formatting:
W3SCHOOLS BOOKS New Books: HTML, CSS JavaScript, and Ajax STATISTICS Browser Statistics Browser OS Browser Display SHARE THIS PAGE Share with
PHP Database
MySQL Introduction MySQL Connect MySQL Create MySQL Insert MySQL Select MySQL Where MySQL Order By MySQL Update MySQL Delete PHP ODBC
< ?php echo date("Y/m/d") . "<br />"; echo date("Y.m.d") . "<br />"; echo date("Y-m-d"); ?>
The output of the code above could be something like this:
PHP XML
XML Expat Parser XML DOM XML SimpleXML
2009/05/11 2009.05.11 2009-05-11
PHP and AJAX
AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX RSS Reader
PHP Date() - Adding a Timestamp
The optional timestamp parameter in the date() function specifies a timestamp. If you do not specify a timestamp, the current date and time will be used. The mktime() function returns the Unix timestamp for a date.
http://www.w3schools.com/php/php_date.asp
3/1/2012
PHP Date() Function
Page 2 of 2
AJAX Poll
The Unix timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
PHP Reference
PHP Array PHP Calendar PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQL PHP SimpleXML PHP String PHP XML PHP Zip
Syntax for mktime()
mktime(hour,minute,second,month,day,year,is_dst)
To go one day in the future we simply add one to the day argument of mktime():
< ?php $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y")); echo "Tomorrow is ".date("Y/m/d", $tomorrow); ?>
The output of the code above could be something like this:
Tomorrow is 2009/05/12
PHP Quiz
PHP Quiz PHP Certificate
Complete PHP Date Reference
For a complete reference of all date functions, go to ourcomplete PHP Date Reference. The reference contains a brief description, and examples of use, for each function!
Previous
Next Chapter
www.BryanUniversity.edu
REPORT ERROR | HOME |
TOP | PRINT |
FORUM |
ABOUT
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2012 by Refsnes Data. All Rights Reserved.
http://www.w3schools.com/php/php_date.asp
3/1/2012