sqlsql-serverbigintsqldatetimesql-convert

Explicit conversion from data type date to bigint is not allowed


This used to work with a column type of DATEIME but now it won't with DATE.

CONVERT(BIGINT,ev.StartDate) * -1

Is there anyway to get a BIGINT value from a DATE column?


Solution

  • Yet another option. This will even flip the sign for you

    Example

    Declare @YourTable table (StartDate date)
    Insert Into @YourTable values ('2017-05-30')
    
    Select DateDiff(DAY,StartDate,-1)
     From @YourTable
    

    Returns

    -42884