Converting Decimal(6,0) Data to SmallDateTime

  • Hello,

    I have a Decimal(6,0) column that contains date data in the following format; ymmdd. So May 1st 2007 looks like this; 70501.

    My first idea as to how to convert this to SmallDateTime would be like this;

    DECLARE @datevalue DECIMAL(6,0)

    SET @dateValue = 70501

    SELECT CONVERT(SmallDateTime,RIGHT(CAST((@datevalue * .000001)AS varchar(8)),6),1) AS NewDate

    Does anyone have a better idea?

    Thank you for your help!

    CSDunn

  • if you data is for dates no older than 2000 and current year is the max(year)

    select

    convert(datetime,'200'+convert(varchar(10),@dateValue),110)

    else

    select convert(datetime,'199'+convert(varchar(10),@dateValue),110)

  • Thanks for your help!

    CSDunn

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

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