I'm trying to evaluate 2 dates in my DVWP, @StartDate (date and time field) and ddwrt:Today(). My expression looks like this:

     <xsl:when test="ddwrt:FormatDateTime(string(@StartDate) ,1033 ,'M/d/yyyy HH:mm:ss') &lt;= ddwrt:Today()">Closed</xsl:when>
              <xsl:when test="@TotalSeats = 0">Unlimited Seating</xsl:when>
            <xsl:when test="@TotalSeats - @FilledSeats = 0 and @TotalSeats != 0">Currently Full</xsl:when>
            <xsl:when test="@TotalSeats - @FilledSeats &gt; 0 and @TotalSeats != 0"><xsl:value-of select="@TotalSeats - @FilledSeats" /> Seats Available</xsl:when>

My issue is the initial when test vever evaluates correctly even though the dates and times are in the correct format from what I can tell. What am I missing here?


What I normally tend to do is convert the dates to YYYYMMDD format for both the @StartDate and the Today(), that way they're 8 digit numbers which I then compare.

  • The hours are important in this, which is causing me grief I think. – Eric Alexander May 12 '11 at 17:33
  • Ah, even YYYMMDDHHmm is out then, as that'd be 12 digits long and I think it only supports 32bit integers (2^32 is a 10-digit number). Try your method but get ddwrt:TodayISO() ? – James Love May 12 '11 at 17:47
  • I can do ddwrt:FormatDateTime(string (@StartDate) ,1033 ,'yyMMddHHmm') and that seems to work, when I try with ddwrt:TodayISO(), the web part bombs out, even though it's inherantly in the same format as @StartDate with no formatting. – Eric Alexander May 12 '11 at 20:20
  • You'll need to wrap Today() in a formatdatetime too, ddwrt:FormatDateTime(string(ddwrt:Today()),1033,'yyMMddHHmm') – James Love May 12 '11 at 20:25
  • I am, I meant that I'm using the excat same code except in place of @StartDate, I've used ddwrt:TodayISO(). The DVWP renders with the generic Unable to view this web part error. – Eric Alexander May 12 '11 at 20:28

YYYMMDDHHmm should work, per James' suggestion in the comments above. Remember that XSL operates on text values, not binary values.

<xsl:value-of select="ddwrt:FormatDateTime(string(@Modified) ,1033 ,'yyyyMMdd HHmmss')"/>
<xsl:value-of select="ddwrt:FormatDateTime(string(ddwrt:TodayIso()) ,1033 ,'yyyyMMdd HHmmss')"/>

Those are the two values you need. Unfortunately, ddwrt:TodayISO() doesn't include the timezone offset, so you still need to monkey around to include that.

Alternatively, you can just do the date comparison in one xsl:when and compare the times only if you need to because the dates match.

  • Thanks Marc, James comments got me on the right track and was able to get it as you were writing this up. – Eric Alexander May 12 '11 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.