0
20110319-04:30:00.772

is the row of Entry_time column from order_report
Above is in varchar
Need to convert in datetime
I am trying the below query but not working
select Convert(datetime,Entry_Time,121) from order_report

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Arjun_Sarankulu
0

The problem is the "dash" in the middle. You'll have to do something about that. Here's some sample code to demonstrate how you might handle it:

declare @myBadDate varchar(25)
declare @myGoodDate varchar(25)
declare @myActualDate datetime
select @myBadDate = '20110319-04:30:00.772'

select @myGoodDate = substring(@myBadDate, 0, charindex('-', @myBadDate)) + ' ' + substring(@myBadDate, charindex('-', @myBadDate) + 1, len(@myBadDate) - charindex('-', @myBadDate))

select @myActualDate = Convert(datetime, @myGoodDate ,121)

select @myBadDate, @myGoodDate, @myActualDate

You can use the above example to figure out how to incorporate the whole substring/charindex thing into your SQL statement.

0

Same is working fine
I have used the following

select Convert(datetime,replace(Entry_time, '-',' '),21) from Order_report

eg:20110319-04:30:00.772
o/p:2011-03-19 04:30:00.773
It adding 1 to mmm but i want the same as 20110319-04:30:00.772
Can any one help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.