Search code examples
sqlsql-server-2008reporting-servicesssrs-2008ssrs-2012

How to calculate timedifference in SSRS


How can we calculate the difference between two datetimes in SSRS. and display the result in a time format

Like for eg:

   Date1                            Date2                     Calculate   
2015-08-02 08:20:00             2015-08-02 10:20:00           02:00:00    

We can easily calculate arithmetic operation, I want to know can we calculate time difference


Solution

  • DateDiff(Hour,Date1,Date2)

    Datediff(Hour,'2015-08-02 08:20:00','2015-08-02 10:20:00')
    

    will result in 2

    time from parts can be used in SQL2012

     timefromparts( Datediff(Hour,'2015-08-02 08:20:00','2015-08-02 10:20:00'),0,0,0,0)
    

    will convert that result to a time format.