Problems converting Date to Numeric

  • Good day all,

    trying to use the code below in order to convert a Date to a numeric datatype.

    SELECT My_DATE,

    Convert(NUMERIC(8,0),CONVERT(CHAR(50), DATEadd(mm,0, My_DATE),112)) AS CheckDate

    from dbo.MyDatabase

    GO

    However I keep getting the error message "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

    I've looked around online for a solution and it was mentioned that I should check for Non-numeric values, which they are as all the reocrds came up when I ran this code:

    SELECT My_DATE

    from dbo.MyDatabase

    WHERE ISNUMERIC(My_DATE)=0

    GO

    So where do I go from here? How do I go about converting these values to numeric ? any help is greatly appreciated.

    Thanks,

    Mitch....

  • Try:

    SELECT My_DATE

    from dbo.MyDatabase

    WHERE ISDATE(My_DATE)=0;

    That's more likely to catch what you're running into.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I agree with GSquared. The error is converting to a DATETIME not to integer.

  • Thanks guys !!

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

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