green
green

Reputation: 713

Format date output of time stamp in php

I'm using the following php command in displaying the time stamp in the table of my database system (postgresql) on a webpage

while ($column = pg_fetch_array($result)) {
    echo "<tr>";
    echo "<td>".$column[0]."</td>";
    echo "</tr>";
}

However the time stamp format is too detailed and how could I simplify it display format for example just '2014-04-18 18:29'

The current output is something like 2014-04-18 18:07:36.978 Thank you in advance for every help.

Upvotes: 0

Views: 60

Answers (1)

h2ooooooo
h2ooooooo

Reputation: 39532

In case you have a timestamp such as Thu, 21 Dec 2000 16:01:07 +0200 (or similar) you can use date and strtotime:

echo date('Y-m-d H:i:s', strtotime($column[0]));

Alternatively, if you use PHP 5.2+, you can use the DateTime class:

$dateTime = new DateTime($column[0]);
echo $dateTime->format('Y-m-d H:i:s');

Upvotes: 1

Related Questions