Converting Decimal Field into a new Date/Time field

  • Is there a way I can convert a decimal field in SQL into a new date/time field?

    The values in the decimal field are like:

    20040818

    So the Month would 8, the day would be 18 and the year 2004.

    Thanks for any help.

    Roger

  • Well, I think the format "YYYYMMDD" is an ISO standard.. So, you can first convert the decimal to a varchar(8) column and then to a datetime column...

    DECLARE @dSomeDec DECIMAL(8,0)

    SET @dSomeDec = 20080818

    SELECT CONVERT( DATETIME, CONVERT( VARCHAR(8), @dSomeDec ) )

    --Ramesh


  • Thank you! That worked.

    I have another conversion issue... I have another decimal field which stores a monetary value in the form of

    393420

    which I want to put into another field in SQL and the resulting field will be Money type.

    If I use this to set the value:

    @Balance/100

    The data appears as 3934.0000

    It appears to be rounding down.

    Any idea how to correct that?

    Thank you.

    Roger

  • Try @Balance / 100.0000

  • It worked. Thanks!

    Rog

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

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