Articles in this section
Category / Section

How to Calculate Difference between Two Dates for the Data Source created with MS SQL

Published:

To obtain the difference between two dates in days, hours, minutes, and seconds, you can use the following expression:

convert(varchar(5),DateDiff(s, 'start_date','end_date')/86400)+'d'+' '+convert(varchar(5),DateDiff(s, 'start_date','end_date')%86400/3600)+':'+convert(varchar(5),DateDiff(s, 'start_date','end_date')%3600/60)+':'+convert(varchar(5),(DateDiff(s, 'start_date','end_date')%60))

Replace the start_date and end_date with the actual dates you want to calculate the difference between.

Example

convert(varchar(5),DateDiff(s, '2017/08/24 06:00:00','2017/08/25 07:00:00')/86400)+'d'+' '+convert(varchar(5),DateDiff(s, '2017/08/24 06:00:00','2017/08/25 07:00:00')%86400/3600)+':'+convert(varchar(5),DateDiff(s, '2017/08/24 06:00:00','2017/08/25 07:00:00')%3600/60)+':'+convert(varchar(5),(DateDiff(s, '2017/08/24 06:00:00','2017/08/25 07:00:00')%60))

image.png

This expression will return the date difference as 1d 1:0:0, which means 1 day, 1 hour, 0 minutes, and 0 seconds.
image.png

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
IJ
Written by Israel Jebaraj Chandirakumar
Updated
Comments (0)
Please  to leave a comment
Access denied
Access denied