1

I am trying to store unix timestamp in mysql with mysql timestamp but when I try to do that it shows 0000-00-00 00:00:00 in mysql

the way I have tried are as follows

table structure in mysql id name timestamp whare id is auto name is varchar and timestamp is timestamp

sql query is "INSERT INTO stocks (ticker, timestamp) VALUES ("harry", "1607485826")"

I have tried another one with datetime as follows from datetime import datetime // imported once only

tmpstp = datetime.fromtimestamp(1607485826)
f'INSERT INTO stocks (ticker, timestamp) VALUES ("harry", {tmpstp})'

1 Answer 1

1

Use

INSERT INTO stocks (ticker, `timestamp`) 
VALUES (@ticker, FROM_UNIXTIME(@timestamp))

where @ticker and @timestamp are parameters placeholders.

For shown parameters values the query will be

INSERT INTO stocks (ticker, `timestamp`) 
VALUES ('harry', FROM_UNIXTIME(1607485826))

PS. I recommend you to rename the column timestamp strongly - this is reserved word in MySQL.

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

2 Comments

thank you so much @Akina you helped me a lot
sir could you please tell me what if I want to use it in python as it is not working through python

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.