Home Tutorial Php Sql Php Sql Timestamp

 
 

Share on Google+Share on Google+
Php Sql Timestamp
Posted on: December 10, 2010 at 12:00 AM
Advertisement
This example illustrates how to create a timestamp type column.

Php Sql Timestamp

This example illustrates how to create a timestamp type column.

In this example the PHP date() function formats a timestamp to a more readable date and time. A timestamp is the number of seconds since January 1, 1970 at 00:00:00 GMT. This is also known as the Unix Timestamp. 

The first parameter in the date() function specifies how to format the date/time. It uses letters to represent date and time formats. Here are some of the letters that can be used:

  • d - The day of the month (01-31)
  • m - The current month, as a number (01-12)
  • Y - The current year in four digits

The second parameter in the date() function specifies a timestamp. This parameter is optional. If you do not supply a timestamp, the current time will be used. In the mktime() function we create a timestamp for tomorrow. The mktime() function returns the Unix timestamp for a specified date.

 

Source Code of timestamp.php 

<?php
  error_reporting(0);

  echo date("Y/m/d");
  echo "<br>";
  echo date("Y.m.d");
  echo "<br>";
  echo date("Y-m-d");

  mktime(hour, minute, second, month, day, year);  
  $tomorrow = mktime(000, date("m"), date("d")+1, date("Y"));
  echo "Tomorrow is ".date("Y/m/d", $tomorrow)."<br><br>";
  
  // time() return current timestamp------
  $nextWeek = time() (24 60 60);
  echo 'Now: '. date('Y-m-d') ."<br>";
  echo 'Next Week: '. date('Y-m-d', $nextWeek."<br>";
  echo 'Next Week: '. date('Y/m/d', strtotime('+1 week'));
?>

Download Source Code

 

Output:

 

Advertisement

Related Tags for Php Sql Timestamp:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com