Results 1 to 3 of 3

Thread: sql, turn string into date

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    sql, turn string into date

    I have a string of a date in my sql server database:

    'wed feb 16 2005'

    How (in sql) do i turn it into a date formatted like this:

    2005-02-16 00:00:00.000

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    Re: sql, turn string into date

    Assuming your string is always in the same format, you could try out something like this:
    Code:
    Select Convert(smalldatetime, SubString(field, Charindex(' ', field, 0) + 1, Len(field)), 101)
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: sql, turn string into date [resolved]

    ended up using something similar

    Code:
     convert(smalldatetime, substring(@datestring,4,len(@datestring) -3))

Posting Permissions

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



Click Here to Expand Forum to Full Width