다음을 통해 공유


FriendlyDateDiff

One function which is often requested from my archived blog posts is dbo.FriendlyDateDiff.

The Function takes two DateTimes and a requested biggest Dimension like days / hours etc.

A sample would be calculating the datediff between My birthdate and the current date:

@Startdate = '19780619 15:15:00',
@EndDate = '20081103 19:33:16',
@BiggestDimension = {PlaceTheDimensionHere}

(Should be something around thirty years ;-) )

Dimension Output
Y 30 years, 9 months, 25 days, 4:18:16
M 369 months, 25 days, 4:18:16
D 11095 days, 4:18:16
Unknown dimension 266284:18:16

Always impressive if you suprise your wife using your wedding day as a starting date and the current date as the end date, using the 'Y' parameter value :-)

The function is as an attachment with this post. Feel free to use and distribute it.

-Jens

dbo.FnFriendlyDateDiff.sql

Comments