how to find the minutes and seconds difference in datetime?

Posted by Prabu_Spark under ASP.NET on 11/11/2012 | Points: 10 | Views : 1130 | Status : [Member] | Replies : 2
Hi sir,
I have two datetime values, i want to find the difference between the seconds in two datetime values. Please help me.


DateTime start_time=11/12/2012 12:05:04 AM;
DateTime end_time=11/12/2012 12:07:27 AM;

Datetime time_difference;

[Note: i want to find the difference between the above datetime values]

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Saratvaddilli on: 11/11/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
to get the difference between two dates we will can use DateDiff function in sql server
declare  @start_time datetime ,@end_time datetime

set @start_time = '11/12/2012 12:05:04'
set @end_time = '11/12/2012 12:07:27'
select DATEDIFF(SECOND, @start_time, @end_time) AS SecondDiff

Result will be 143 seconds

in the above code snippet we had declared the starttime and endtime
By using the DateDiff function we got the diffrence between two dates in seconds
these are some other formats of DateDiff function

SELECT DATEDIFF(DAY, GETDATE(), GETDATE() + 1) AS DayDiff

SELECT DATEDIFF(MINUTE, GETDATE(), GETDATE() + 1) AS MinuteDiff
SELECT DATEDIFF(SECOND, GETDATE(), GETDATE() + 1) AS SecondDiff
SELECT DATEDIFF(WEEK, GETDATE(), GETDATE() + 1) AS WeekDiff
SELECT DATEDIFF(HOUR, GETDATE(), GETDATE() + 1) AS HourDiff


Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 11/12/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi Prabu_Spark if this helps you please mark as answer that may help others who searching for the same

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response