views:

1549

answers:

2

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"
A: 

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

ChrisBD
+2  A: 

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'
  */
Jose Basilio
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
vineet