Duration (HH:MM) calculation between two time stamps

Datediff function or variations of it work fine generally but… if you want to have exact duration in Hours:Minutes or HH:MM format. You gotta do what you gotta do one of which is as follows.

This basically rounds off the hour and then uses mod function to calculate minutes.

 =(DateDiff(DateInterval.Hour,Fields!StartTime.Value,Fields!EndTime.Value)) & ":" & ((DateDiff(DateInterval.Minute,Fields!StartTime.Value,Fields!EndTime.Value)) mod 60) 

The code is written in SSRS expression format but can be converted into other formats easily and frankly if you cant then you are doing the wrong job.

Yeah I know its not exactly a huge deal but might help someone out there along with millions of solutions out there. So cheer up!


IT professional with wider interest in technology

Tagged with: , , ,
Posted in tsql, Uncategorized, vbscript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: