Welcome to MSDN Blogs Sign in | Join | Help
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

Posted: Monday, November 03, 2008 6:46 PM by Jens K. Suessmeyer

Attachment(s): dbo.FnFriendlyDateDiff.sql
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker