Integer to datetime, anyone?

  • Hi there,

    Googled the internet, found the question posed several times, no answer however! I have this integer value always as format 20040522, yyyymmdd. I wish to convert this to datetime. When looking in BOL under CAST and CONVERT I see that this is an implicit conversion. I translate this as: put a recognizable integer into a datetimefield, and it will be stored as such.

    Not so. At least, I don't get it to work. Maybe you guessed, I'm trying to do something with the sysjobhistory table, where date is stored in this format. I've tried several converts, no luck sofar. I thought this should be simple, but...

    TIA,

    Hans Brouwer

    Greetz,
    Hans Brouwer

  • Not sure if I understand you, but are you looking for something like this:

    DECLARE @a INT

    SET @a = 20040522

    SELECT CONVERT(DATETIME,CONVERT(CHAR(8),@a,112))

    ------------------------------------------------------

    2004-05-22 00:00:00.000

    (1 row(s) affected)

    ???

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • That's it, tnx. And I know what I did wrong now, so tnx again.

    Greetz,
    Hans Brouwer

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

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