Date And Time Scripts In PHP

by Hiroshi on June 13, 2008

in Date & Time

Date and time in PHP is very useful and handy because it provides you the result of time and date, in the way you want. Using Date and Time functions in flash we can display date and time at website in a number of ways and formats. Below are some examples and best practices.

Below the script shows you how to create and use the date and time functions.

echo date("D M d, Y H:i:s");


echo "The time is ";
echo date('H:i:s'); // Hours, minutes, seconds
echo " and the date is ";
echo date('j F Y'); // Day name, month name, year

This will output: Fri Jan 03, 2003 12:01:21 (or the current date/time)
To change the formatting of the date and time you only need to change the syntax in the quotes to suit your new purpose.

echo date("D, d.m.Y");

It will provide you with this result. i.e. (Tue, 13.06.2006)

Simply put this code into your web page and save webpage in php extension and you will get date and time displayed at your website.


// Assuming today is: March 10th, 2001, 5:16:18 pm
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month
$today = date("H:i:s"); // 17:16:17

More Resources

Related Posts

Previous post:

Next post: