Float to Date

  • I have a database from a vendor that has the date/time stored as a float.

    Example: 20070809100330.0

    I think it is YYYYMMDDHHMMSS

    I would like to convert that into a date time, but I am totally stumped. I tried casting/converting it to a varchar and then doing string functions on it, but I can't get the desired results.

  • declare @f float
    set @f =20070809100330.0
    select convert(datetime,stuff(stuff(stuff(convert(bigint,@f),9,0,' '),12,0,':'),15,0,':'))
    
  • Michael, I would buy you a beer if I could for that syntax. I was nowhere near that. Worked like a charm, Thanks!

  • There's always paypal .

  • Heh... forget PayPal... UPS will ship a keg

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Paypal does that too .

Viewing 6 posts - 1 through 6 (of 6 total)

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