0

how to change these Date Time strings to sql server DateTime Type:

"Thu May 07 19:19:27" 
"Thu May 07 19:19:33" 
"Thu May 07 19:19:34" 
"Thu May 07 19:19:34"
"Thu May 07 19:19:35" 
1
  • 1
    A comment on the edit: I'd put the datetime strings in quotes (for colorization purposes), and also change the sentence above to clarify that they are strings. But I don't have enough rep... :P Commented May 12, 2009 at 10:08

2 Answers 2

2

Here's a snippet of TSQL that you may be able to use in a stored procedure or function to convert the strings into SQL DateTime.

  DECLARE
     @Year char(4), /* the DateTime needs a year */
     @DateString varchar(20),
     @DateVariable DateTime;

  SET @Year = '2009';
  SET @DateString = 'Thu May 07 19:19:27';  /* any of the dates in your list */

  SET @DateVariable = CONVERT(DateTime, @Year 
                            + SUBSTRING(@DateString, 4, LEN(@DateString)));

  /*
      After the conversion, @DateVariable contains '2009-05-07 19:19:27.000'
  */
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much. Generally i don't post questions on internet because getting answers sometime takes hours to days. i always tries to get references from posts which already has been answered. today i was attending a meeting and was doing some timepass. suddenly, i just posted a question (i was struggling with this problem since morning.) on this site first time. and, within minutes i got 4-5 replies. i am very very thankful to all of you. Now, on this is my favorite place for any programming related queries. you people rocks. once again, thank you very much to all of you. vineet
0

Are you looking at converting those date strings into DateTime values using an SQL stored function/procedure or in some external program?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.