Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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>
   <xsl:choose>
     <xsl:when test="ddwrt:FormatDateTime(string(@StartDate) ,1033 ,'M/d/yyyy HH:mm:ss') &lt;= ddwrt:Today()">Closed</xsl:when>
        <xsl:otherwise>
          <xsl:choose>
              <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>
           </xsl:choose>
         </xsl:otherwise>
    </xsl:choose>
</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?

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

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.

share|improve this answer
    
The hours are important in this, which is causing me grief I think. –  PirateEric 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. –  PirateEric 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. –  PirateEric May 12 '11 at 20:28
show 1 more comment

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.

share|improve this answer
    
Thanks Marc, James comments got me on the right track and was able to get it as you were writing this up. –  PirateEric May 12 '11 at 20:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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