Tuesday, March 1, 2011

DateDiff in SharePoint Data View

How many consultants does it take to figure out how to calculate Date Differences in SharePoint 2010 xPath 1.0?
3.
And guess who figured it out?  The BA.
(ddwrt:DateTimeTick(ddwrt:FormatDate(ddwrt:GenDisplayName(string($thisNode/@DueDate)), 1033, 1)) - ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))) div 864000000000
The Formula Deconstructed
Get the Ticks for the “Due Date” assuming DueDate is the SharePoint List column you want to use and EN-US is the locale you want to use (LCID 1033):
(ddwrt:DateTimeTick(ddwrt:FormatDate(ddwrt:GenDisplayName(string($thisNode/@DueDate)), 1033, 1))

Get the Ticks for the Current Date but you can replace $Today with another SharePoint List column:
ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))

Subtract the two.

Then Divide by the number of Ticks in a day, 864000000000.

Ann:  1.  SharePoint Designer: 0.

2 comments:

  1. Thank you for a solution!

    And could Sharepoint team possibly make the most simple things that every other platform has been able to do for many years more difficult???

    ReplyDelete
  2. Your code is working. I've been battling with this for about a week. Kinda silly that I had to fight so hard for something that seems like it should have been really easy.

    ReplyDelete