Qbik
Qbik

Reputation: 6147

T-SQL convert BigInt into Date

I used to work this way :

select cast(cast(20171002 as varchar) as date) AS BigInt_into_Date,

but is it possible, to achive the same with single use of convert() function ? Conversion between bigint and datetime is explicite, so expression argument in convert is needed, so mayby we also could convert into date

Upvotes: 2

Views: 1318

Answers (1)

Brett
Brett

Reputation: 1550

It is possible to convert from BigInt to DateTime.

However, the numeric value for October 2nd 2017 is 43008 (days since Jan 1, 1900).

20171002 is really a string representation of a date stored as a number - hence your need for the double cast.

And no - I don't think it's possible to perform any simple arithmetic to get from 20171002 to 43008 :-)

Upvotes: 2

Related Questions