Home > Blockchain >  How to cast INT > DATE in mySQL (Fiddle code)?
How to cast INT > DATE in mySQL (Fiddle code)?

Time:11-30

i have airbnb data and i want to cast column last_reviews (which datatype is int) to date this is my sql code http://sqlfiddle.com/#!9/b5ea42/31

how do i cast int > date? or how do i create last_reviews column as datatype date?

CodePudding user response:

The last_review date seems to be the number of days since 1900-01-01 so in MySQL you would:

SELECT '1900-01-01'   INTERVAL last_review DAY AS last_review_date
FROM ...

The result checks out for the sample data (which you should delete).

CodePudding user response:

last_review values looks like VB(A) numeric representation for dates. If so then test this:

SELECT last_review, '1900-01-01'   INTERVAL last_review DAY
FROM airbnb

Adjust constant part (maybe it must be '1899-12-31'?) if needed.

  • Related