Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting a Date stored in the DB

Tags:

date

php

datetime

I'm updating some very old PHP (3 I think) to PHP 5.6 and am having problems getting the time formatted for old posts. The date is stored in the MySQL database and I can retrieve that fine - but the old code delivers a null output. Everything I read about formatting seems to assume I want the current date. I want to 2012-11-09 14:17:18 to just read 2012-11-09 14:17

Here is the original code from the ancient version of the phorum:

$datestamp = date_format($head_row["datestamp"]);
echo $datestamp

but that produces an empty nothingness, so I changed it to:

$datestamp = ($head_row["datestamp"]);

and that gives me the whole saved datestamp. How do I cut off the seconds?

like image 455
D Rice Avatar asked Dec 08 '25 10:12

D Rice


1 Answers

I think what you are looking for is strtotime.

$datestamp = date('Y-m-d H:i', strtotime($head_row["datestamp"]));
like image 99
Bart Scheffer Avatar answered Dec 10 '25 03:12

Bart Scheffer