Ever wonder how some website display or show the current date in their web pages? its simple really, PHP has a function called date() that you can display dates in many different ways. I use it frequently when i am developing website for our customer.

I am with Webune.com and I manage wallpaperama.com. The team at wallpaperama often want a feature added to their wallpaperama website. I remember one day, i was asked to show the current date so i did it with the date() function in PHP.

These are my notes i have - want to share them here just in case it benefits someone out there..

If you want to see it in action, i wrote up this small snippet to show you how it works:

Copy and paste the following into your editor or text editor like notepad:
CODE:
<HTML>
<HEAD>
<TITLE>Displaying Your Hostname or Sitename by Wallpaperama.com</TITLE>
</HEAD>
<BODY>
 <p>This Script was developed by <a href="http://www.wallpaperama.com">Wallpaperama.com</a> - Support us by telling your friends about wallpaperama and help contribut to the open source by adding your knowledge of PHP, Linux, Mysql and more to others, just like this script.</p>
 <p><strong>Your Hostname is: <?php echo date("M d, Y");?></strong></p>
 <p>Thank You</p>
 <p>Wallpaperama Team</p>
 <p align="center">Visit <a href="http://www.wallpaperama.com">Wallpaperama.com</a> Today </p>
</BODY>
</HTML>


Now save as date.php and uploaded it your site, then open it with your browser and it will display today's date

NOTE: you will need to have PHP in your web plan. If you don't have a PHP hosting plan, you can visit us at www.webune.com to sign up to one of our popular php/mysql plans

here is my notes i was telling you about:

CODE:
####################### EXAMPLES ##########################
<?php
// 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
?>


<?php
$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"),  date("Y"));
$nextyear  = mktime(0, 0, 0, date("m"),  date("d"),  date("Y")+1);
?>

<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');


// Prints something like: Monday
echo date("l");

// Prints something like: Monday 15th of August 2005 03:12:46 PM
echo date('l dS \of F Y h:i:s A');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

/* use the constants in the format parameter */
// prints something like: Mon, 15 Aug 2005 15:12:46 UTC
echo date(DATE_RFC822);

// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>


Webmaster

Wallpaperama Team