PHP: strtotime () always returns 01/01/1970

I try to display dates in European format (dd/mm/yyyy)s strtotime, but always returns 01/01/1970.

Here is my code:

echo "<p><h6>".date('d/m/Y', strtotime($row['DMT_DATE_DOCUMENT']))."</h6></p>";

In my database, the field is varchar and the entries are formed as yyyy.mm.dd

I use the same code line for another field, which is formed as yyyy-mm-dd (also varchar), and it works fine.

Thank you for your help.

+5
source share
3 answers

Since the format yyyy-mm-ddworks, try replacing .with -:

date('d/m/Y', strtotime(str_replace('.', '-', $row['DMT_DATE_DOCUMENT'])));
+4
source

Try:

$date = date_parse_from_format("Y.m.d", $row['DMT_DATE_DOCUMENT']);
$time = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
echo "<p><h6>".date('d/m/Y', $time)."</h6></p>";

(Using date_parse_from_format()instead strtotime())

Or simply:

$date = date_parse_from_format("Y.m.d", $row['DMT_DATE_DOCUMENT']);
echo "<p><h6>{$date['day']}/{$date['month']}/{$date['year']}</h6></p>";
+3
source

strtotime PHP.

m/d/y d-m-y , : (/), m/d/y; (-) (.), d-m-y.

, ISO 8601 (YYYY-MM-DD) DateTime::createFromFormat(), .

YYYY-MM-DD, d.m.y.

, date_create_from_format

,

date_create_from_format('Y.m.d',$row['DMT_DATE_DOCUMENT'])
+2

All Articles