425-882-1032 info@3sharp.com

Recently, a colleague and I were trying to filter a SharePoint Data View Web Part to display only list items with a start date of today or some date in the future. Using SharePoint Designer 2010, we could not find a way to use built-in functions in the GUI to compare two date values. So, we did the next best thing: we converted both date values to numbers and then compared those values.

SharePoint uses ISO values for columns that are of the Date data type. The format for these values is “yyyy-MM-ddTHH:mm:ssZ”. With XSLT, you can first use the substring-before function to grab everything in the date string before the “T”. Then, you can use the translate function to remove the “-” characters. Finally, you can use the number function to convert the string to a number and then do your date comparison. The following screen shot shows how the XSLT expression appears in the SharePoint Designer GUI.

Comparing Dates with XSLT

I poked around on the Web for alternative ways of doing a date comparison. I found this thread, where it was suggested that the ‘yyyyMMdd’ modifier could be used for the string function. I bet that approach and maybe some others are cleaner than what we came up with…I am just glad we found something that worked.