How to use Date Function in PHP

PHP

Date is the Important facility and Function used in PHP. Date function is very much flexible ,deep to think ,understand and use it in many examples. Date is used to show current date , time , before dates , after dates ect. We can play with the date features . We have taken some of the examples for the knowledge of how to use it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example for Using Date Function in PHP</title>
</head>
<body>
<?php
echo '<br>';
echo date("Y/m/d") . "<br>";
echo date("Y.m.d") . "<br>";
echo date("Y-m-d");

echo '<br>';

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);

echo '<br>';

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

// Prints something like: Monday
echo date("l");
echo '<br>';
// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');
echo '<br>';
// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
echo '<br>';
/* use the constants in the format parameter */
// prints something like: Mon, 15 Aug 2005 15:12:46 UTC
echo date(DATE_RFC822);
echo '<br>';
// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));

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

?>
</body>
</html>
-->