Mar
Mar

Reputation: 5

SQL cast int to datetime

Why does this SQL statement:

Select cast(convert(1231231231,103) AS datetime)

cause an error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '103) AS datetime)' at line 1

I need to convert INT to DATETIME, how to make it work?

Upvotes: 0

Views: 4296

Answers (1)

user1538943
user1538943

Reputation:

Since your integer is unix time you can use FROM_UNIXTIME(unix_timestamp): https://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime?

Upvotes: 1

Related Questions