![]() |
![]() |
DATE |
timestamp |
No |
CURRENT_TIMESTAMP |
A timestamp in structure view
Below is an example of a timestamp and how it is structured.
A timestamp isn't easy to read by humans so we will need to format it.
In the following code example we use the PHP function strtotime() to convert our textual timestamp into a Unix timestamp.
Now that we have a Unix timestamp we can utilise the date() function.
date(desired format, your timestamp)
to format a timestamp into a UK format we would use date("d/m/y”, your timestamp);
<?
$timestamp = "2015-11-15 20:34:35";
$date = strtotime($timestamp);
$formatedDate = date("l d/m/Y",$date);
$hourMin = date('H:i',$date);
echo $formatedDate;
echo '<br />';
echo $hourMin;
?>
The above code would output
Sunday 15/11/2015
20:34
Retrieving a timestamp from a MySQL database.
<?php
$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD,
DATABASE_NAME);
$sql = mysqli_query($dbc, "SELECT 'date' FROM `table`") or die("Error: ".mysqli_error($dbc));
while($row=mysqli_fetch_array($sql))
{
$xDate = strtotime($row['DATE']);
$yDate = date("d/m/y",$xDate);
$hourMin = date('H:i',$xDate);
}
?>
Keywords: Latest Posts |
27/04/20 |
How to Make a Model Anderson Shelter |
25/04/20 |
How to make a Model Roman Villa |
15/04/20 |
How to Make a Tetrahedron |
07/04/20 |
Octahedrons and how to draw their net |
17/11/15 |
How to Create a Time Sheet in Excel |
15/11/15 |
Handling time and dates in PHP |
03/02/15 |
How to Enhance Photographs with the Gimp |
25/01/15 |
How to Cook Pigeon |
25/01/15 |
Telling the Time |
24/01/15 |
An Old Travel Card |