Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
PHP Time and Date (0 Comments)
Admin: Posted Date: March 3, 2010

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. Please remember that the letters ARE case sensitive.

PHP Time and Date

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;
?>

 

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: