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

As these functions are built in PHP , no installation is necessery. date() - You can pickup the current date using date function. The date can be displayed in different formats using the "format" parameter of the date().

Using Date and Time functions in PHP

Installation

As these functions are built in PHP , no installation is necessery.

date() - You can pickup the current date using date function. The date can be displayed in different formats using the "format" parameter of the date()

string date ( string format [, int timestamp ] )

<?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
echo $today."<br>";
$today = date("m.d.y"); // 03.10.01
echo $today."<br>";
$today = date("m/d/y"); // 03/10/01
echo $today."<br>";
$today = date("j, n, Y"); // 10, 3, 2001
echo $today."<br>";
$today = date("Ymd"); // 20010310
echo $today."<br>";
$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
echo $today."<br>";
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day.
echo $today."<br>";
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
echo $today."<br>";
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month
echo $today."<br>";
$today = date("H:i:s"); // 17:16:17
echo $today."<br>";
?>

Time() functions

We can get the current Unix time stamp by using time() function

<?php
$currenttime=time();
echo "Current Unix timestamp".$currenttime."<br>";
echo "Current Date :".date("d m y",$currenttime)."<br>";
echo "Current Time :".date("h:m:s",$currenttime)."<br>";
//get the time after 7 hours
$timeinfuture = strtotime("+7 hours");
echo "Unix timestamp after 7 hours :".$timeinfuture."<br>";
echo "Time after 7 hours :".date("h:m:s",$timeinfuture)."<br>";
//get the time after 7 days
$timeinfuture = strtotime("+7 days");
echo "Unix timestamp after 7 days :".$timeinfuture."<br>";
echo "Date after 7 days :".date("d m y",$timeinfuture)."<br>";
?>

 

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

Comments: