So here’s a fun one that we at SharePoint Rx were struggling with the other day.
We were creating a dashboard using the DVWP in SharePoint Designer 2010 and had to perform some date comparisons to control the display of indicators. If you’ve used SPD in the past, you know that the goal is to NOT write code, but to use the “coding by clicking” capabilities of SPD and allow it to write the code (in this case XSL) to control your conditional formatting. Every time I use SPD for something like this, I always seem to run into a new problem, even though I know it should be a simple task.
“Am I the only one with this issue?” he asks.
Here’s the end goal…to display a status indicator for tasks to indicate whether they were completed on time, completed late, not complete and not late, and not complete and late. You can see the four icons I chose to indicate these statuses.

My “conditions” are as follows:
Status equals “completed” and Due Date >= Completed Date
Status equals “completed” and Due Date < Completed Date
Status not equals “completed” and Due Date >= [Current Date]
Status not equals “completed” and Due Date < [Current Date]
One of the issues you immediately experience is the comparison of date values. Using SPD, I did an “un-advanced” comparison in my condition statements and never got the correct results. SPD wrote some XSL like this (I broke it up so it’s a little easier to read):
<xsl:if test=”normalize-space($thisNode/@Status) = ‘Completed’
and
ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/@DueDate))) >=
normalize-space(@Completed_x0020_Date)” ddwrt:cf_explicit=”1″>
<img src=”_layouts/images/kpinormal-0.gif” width=”16″ height=”16″ />
</xsl:if>
So we have a “Due Date” that has been operated on by ddwrt:DateTimeTick (see if you can find any documentation on this function) and is returning the number of days from January 1, 1900 comparing to the “Completed Date” in the form “MM/DD/YYYY.” That doesn’t work!
Sidebar rant…Come on, Microsoft! The only documentation on the ddwrt namespace is from a non-MS person (Serge van den Oever ) and is from 2005…for SharePoint 2003?
So, let’s look at the “Advanced” condition criteria that does work.

We used the completely undocumented ddwrt:DateTimeTick function and applied it equally to both dates.

When performing the comparison with [Current Date], here’s what we did.

We were successful with using the $Today variable, but I’ve seen others who have also used ddwrt:Today.

Here are the criteria for all four conditions.
@Status = ‘Completed’ and ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@DueDate))) >= ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Completed_x0020_Date)))
@Status = ‘Completed’ and ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@DueDate))) < ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@Completed_x0020_Date)))
$thisNode/@Status != ‘Completed’ and ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/@DueDate))) >= ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))
$thisNode/@Status != ‘Completed’ and ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/@DueDate))) < ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))
Now, I’d like to believe that features in SPD 2010 that were in SPD 2007 were all functioning correctly, but I seem to have lots of problems using the “All formatting visible” functionality. I found that each time I changed this I must
Not sure what that’s about or if it’s just one of my settings, but it sure is annoying.

Of course, the idea is that you want to make all your conditionally formatted elements visible so you can easily work on them.

FYI, if you want to determine which condition applies to which element, you can select the condition and you should notice a highlighting of the element to which the condition corresponds.

Keywords:
Conditional formatting
SharePoint Designer 2010
Date comparison
Data view web part
ddwrt namespace