I have table called Data_Details and the data looks like:
DateTimeClosed Datesub TimeSub
6/20/2011 18:00 5/16/2011 17:13:17
6/20/2011 18:00 5/18/2011 13:45:17
6/1/2011 19:00 5/24/2011 8:30:12
I am trying to get the difference between closed date and sub date in mins.
I wrote something like this:
SELECT convert(int,convert(Datetime,[DateTimeClosed])-
(convert(Datetime,[Datesub])+convert(datetime,[TimeSub])))*24*60
FROM dbo.Data_details
It is giving me following error:
Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.
Can anyone help me?
This returns time difference in seconds:
Sample script:
UPDATE– Using varchars now that OP clarified that they are all varchars: