Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    29

    Unanswered: string to datetime

    Hi all,
    I have a string containing a formatted date like

    'Tue, 07 Jun 2016 12:13:20 +0000'

    and I need a way to convert it to store it into a datetime field.
    The PARSE function doesn't work since I'm using SQL Server 2008.

    Is there a smart way to do it?

    Thanks a lot

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    A lot depends on the file format, the tools you have available, etc. I'd probably use an SSIS package if there were many rows or other complex ETL manipulations.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jan 2012
    Posts
    29
    Hi Pat,
    thanks for your answer.
    Actually, I just need to make this conversion once within a ODBC connection, so it needs to be just a SQL statement.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Messy as heck, but:
    Code:
    DECLARE @c VARCHAR(99) = 'Tue, 07 Jun 2016 12:13:20 +0000';
    
    SELECT Cast(Substring(@c, 1 + CharIndex(',', @c), CharIndex('+', @c) 
    -  CharIndex(',', @c) - 1) AS DateTime)
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •