I have a column that's a text:
Remarks (text, null)
A sample value is
"5/21/2013 9:45:48 AM"
How do I convert it to a datetime format like this:
"2013-05-21 09:45:48.000"
The reason for the conversion is that I was trying to get the total number of hours between a datetime column and the date stamp in the Remarks column. I was thinking of something like this:
Remarks (text, null) - Date_Sent (datetime, null)
To be clear, the columns represent the datetime an inquiry by a customer was sent (Date_Sent
) and the last response made by a representative regarding the inquiry (Response
), so for a sample of a Date_Sent
having a value of "2013-05-21 08:00:00.000"
and a Response
with a value of "5/21/2013 10:00:00 AM"
, I should get a value of 2.00
(2 hours). Unfortunately, in the database I'm working on, Remarks
is a text and Date_Sent
is a datetime.
This works:
SELECT STR_TO_DATE(dateColumn, '%c/%e/%Y %r') FROM tabbleName WHERE 1
In SQL Server , cast text as datetime
select cast('5/21/2013 9:45:48' as datetime)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With