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

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.