Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Convert epoch to MySQL DateTime format

I have to store epoch timestamps into a MySQL database DateTime column. I need to be able to convert the epoch into the DateTime form to be able to add it to the database. The epoch data is grabbed from an external source so we have no control over that, the database is also established and should be left as it is. We just need to be able to convert between the two in PHP.

like image 873
Peter Bushnell Avatar asked Dec 10 '22 19:12

Peter Bushnell


1 Answers

PHP

date("Y-m-d H:i:s",$epochTS);

MySQL

FROM_UNIXTIME(timestampColumn)

Nothing more to it

like image 169
Hanky Panky Avatar answered Dec 21 '22 04:12

Hanky Panky