D
D
Dreaded2018-05-19 14:55:13
MySQL
Dreaded, 2018-05-19 14:55:13

How to save timestamp from php to MySQL?

I'm trying to send data to the database as a timestamp from PHP, but it always gives me an error:

Incorrect datetime value: '1526763600' for column 'expiration_date' at row 1

I tried setting the field type and datatime and timestamp in MySQL - it still doesn't help. How all the same it is correct to store in a DB time and date in the timestamp format? Or just set the field type to INT and don't worry?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-05-19
@Dreaded

Use the FROM_UNIXTIME function to convert input parameters to the timestamp data type:
Checking the result:

SELECT UNIX_TIMESTAMP(expiration_date) FROM you_table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question