PHP Time and Date

by Varun Thirayan
APDZ.com

Dates

Dates are very simple in PHP and are easy to get the hang on but not so easy to remember all the variables to the dates as you will see further on in this tutorial.

In PHP time and dates, you use different letters to display different formats of the date as shown below. Remember that the time and date will be the one that the server is set to.

Please remember that the letters ARE case sensitive. So g and G are two different things.

<?php
// This will display something like June
// F simply means the full name of the month (January-December)
echo date("F");
?>


If you wanted to display something a little longer than just the month, you can also input code such as below.

<?php
echo date("l dS of F Y");
?>


This will display something like Wednesday 19th of December 2005.

l = Full Day
d = Date
s = Suffix of the date (st, th)
F = Full Month
Y = Full year


As you may have noticed you can out real words in such as of and it will not affect the code but is advised to put most of the code outside the date tag.

Time

Time can also be displayed as below:

<?php
// Could display 07:25:56 PM
echo date("h:i:s A");
?>

Extras - Variables

You also put date as a variable.

<?php
$time = date("l dS of F Y");

// Could display 07:25:56 PM
echo $time;
?>


Find out more about variables by clicking here.


Options:
Printer Friendly
Email Friend

About The Author:

© Varun Thirayan http://www.apdz.com

Developer Categories



Developer Tutorials
ASP
CGI & Perl
CSS
Flash
HTML
Java
JavaScript
MySQL
PHP
Python
XML

Developer Documentation

Developer Tools



Search our Developer Tutorials
  The DevSyndicate Network