Thursday, May 21, 2009

Date Comparison in XSL

Since XSL in SharePoint Designer does not have a very good support for date comparisons. I Googled for at least more than half of the day for a decent date comparison and came across this post as a solution by ma man Kotendra. However, this post assumes that date is provided in ISO format (YYYMMDD). This was not my case…so I Googled bit more and bit more and little bit more :o) and here is the solution.

Below is the formula (XSLT Filtering) to compare dates in SharePoint Designer using XSL:


[
number(ddwrt:FormatDateTime(ddwrt:FormatDate(string(@Open_x0020_Date),1033,1),1033,'yyyyMMdd'))
>=
number(ddwrt:FormatDateTime(ddwrt:FormatDate(string($varFromDate),1033,1),1033,'yyyyMMdd'))
]


Above formula will convert date 5/31/2009 into 20093105 and treat it as a number to compare with another number converted from date.

Thanks!

2 comments:

  1. Shouldn't it be converted to 20090531 to get a good comparason? Year Month Day.

    200905311330 for 13:30 or 1:30 PM for time to be included

    ReplyDelete
  2. Its actually the same approach.

    ReplyDelete

Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...