Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
alejo46
Posting Yak Master
157 Posts |
Posted - 2010-03-27 : 16:27:46
|
I need your helpIve got a table named TABLEX that contains 2 fields: started_date and ended_date, both are datetime type with the format YYYYMMDD HH:MM:SS.XXX.In order to calculate the duration time, how can i substract two datetimes values and get the result in anothe columan?; in the example below, i use this with convert function.select field1, started_date, ended_date, convert(varchar,ended_time,114) - convert(varchar,started_date,114) as "Duration Time" from TABLEX but i've got an error basically saying that ocurred and error mistmath data types. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-28 : 02:32:22
|
quote: Originally posted by alejo46 I need your helpIve got a table named TABLEX that contains 2 fields: started_date and ended_date, both are datetime type with the format YYYYMMDD HH:MM:SS.XXX.In order to calculate the duration time, how can i substract two datetimes values and get the result in anothe columan?; in the example below, i use this with convert function.select field1, started_date, ended_date, convert(varchar,ended_time,114) - convert(varchar,started_date,114) as "Duration Time" from TABLEX but i've got an error basically saying that ocurred and error mistmath data types.
you want duration as integer value or in hh:mm:ss format?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-03-28 : 03:44:33
|
SELECT CONVERT(CHAR(8), Ended_Time - Started_Date, 8)FROM TableX N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|
|