4

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.

1

3 Answers 3

15

PHP

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

MySQL

FROM_UNIXTIME(timestampColumn)

Nothing more to it

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks, the PHP you have expresses the date exactly as it is in the database,
0

No need to do any convert for MySQL or PHP just or enter the same to database

echo date('r', $epoch);

strotime() is the function used to convert datetime to epoch. Documentation

Comments

0

strotime() is the function used to convert datetime to epoch. Documentation

time() is the function used to convert epoch to datetime. Documentation

1 Comment

also read this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.