thanks and I am sorry, but i had two things mixed up. so, it is good. but Is there a way to do datediff and get result in mm:ss formate?
Try
select cast(datediff(SS,'11/18/2012 23:54:06','11/18/2012 23:56:16')/60 as varchar)+':'+cast(datediff(SS,'11/18/2012 23:54:06','11/18/2012 23:56:16')%60 as varchar)
go
Many Thanks & Best Regards,
HuaMin Chen
Marked as answer by Arial12 on Nov 21, 2012 04:21 PM
Arial12
Member
29 Points
160 Posts
DATEDIFF not giving accurate result
Nov 19, 2012 09:36 PM|LINK
Hi,
for some reason datediff in my sql query is not giving correct or expected result.
for example,
I am doing select datediff(SS,'11/18/2012 23:54:06','11/18/2012 23:56:16') give me 130 but i think it should give me result with 70 seconds.
can someone tell me what is worng with this statement?
Thanks,
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: DATEDIFF not giving accurate result
Nov 19, 2012 09:42 PM|LINK
I think it should be 130. Why do you think it should be 70?
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: DATEDIFF not giving accurate result
Nov 19, 2012 09:52 PM|LINK
One minute has 60 seconds in it. The math should return 130 seconds for you.
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
Arial12
Member
29 Points
160 Posts
Re: DATEDIFF not giving accurate result
Nov 19, 2012 10:48 PM|LINK
thanks and I am sorry, but i had two things mixed up. so, it is good. but Is there a way to do datediff and get result in mm:ss formate?
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: DATEDIFF not giving accurate result
Nov 19, 2012 10:56 PM|LINK
divide by 60. The quotient is the minutes part. The modulus is the seconds part. The rest is simple formatting.
wmec
Contributor
6228 Points
3226 Posts
Re: DATEDIFF not giving accurate result
Nov 20, 2012 01:11 AM|LINK
Try
select cast(datediff(SS,'11/18/2012 23:54:06','11/18/2012 23:56:16')/60 as varchar)+':'+cast(datediff(SS,'11/18/2012 23:54:06','11/18/2012 23:56:16')%60 as varchar)
go
HuaMin Chen