Date stored as a Decimal

  • Hello,

    I am querying a table and can get the required results all ok, however all of the date fields are stored in the decimal datatype format. Ie for a row of the date 27/01/2009 (dd/MM/yyyy) the actual filed contains this 131662107.

    I need to try and convert 131662107 to 27/01/2009 (dd/MM/yyyy)

    Any help would be appreciated.

    Kind Regards

    Nathan

  • Try using Cast(yourDecimalColumn As datetime), i.e.

    Declare @myDate decimal;

    Set @myDate = 39838;

    Select Cast(@myDate As datetime);

  • If the date is stored as a number it should not be this big!

    declare @DateTest datetime

    set dateformat dmy

    set @DateTest = '27/01/2009'

    select @DateTest

    ,convert(int,@DateTest) IntDate

    ,convert(decimal,@DateTest) DecimalDate

    The int for your '27/01/2009' date is 39838.

    Even if you push to the limit we are nowhere near 131662107...

    declare @DateTest datetime

    set dateformat dmy

    set @DateTest = '31/12/9999'

    select @DateTest

    ,convert(int,@DateTest) IntDate

    ,convert(decimal,@DateTest) DecimalDate

    Trying to convert 131662107 results in an arithmetic overflow

    declare @DecimalTest decimal

    set @DecimalTest = 131662107

    -- Arithmetic overflow...

    select convert(datetime,@DecimalTest)

    Missing a piece of the puzzle, maybe it's something I don't know about dates...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply