views:

65

answers:

1

Hi, I have two dates in the following format:

1) <xsl:value-of select="ddwrt:FormatDateTime(string(@Status_x0020_Date) ,1033 ,'yyyy-MM-dd ')" />

2)<xsl:value-of select="ddwrt:FormatDateTime(string(../../../Strategic_Items_Daily_Status/Rows/Row/@Status_x0020_for_x0020_Last_x002) ,1033 ,'yyyy-MM-dd ')" />

I am using SharePoint Designer to create a condition to compare these values. Status Date should be greater than or equal to Status for Last Month.

I started with checking if Status Date is greater than or eqal to Status for Last Month but I think SPD gets the "translate" wrong. Any ideas?

    [@Item_x0020_ID = $dvt_ParentRow/@ID and 
number(translate(substring-before(../../../../../../../../../Rows/Row/@Status_x0020_Date,'T'),'-','')) 
<= number(translate(substring-before($Today,'T'),'-',''))]

The output of the dates on the page are like 2010-09-01.

Thanks in advance.

Edit: the problem is that I don't get any output, only if I have status date is not equal to status for last month.

A: 

You don't need the number function, if the two textual values are both numbers it'll just compare them as if they were.

I suspect your problem may be your use of <= as a comparator; you'll need to escape the < with &lt; instead, and use &lt;=.

As far as doing a date difference goes, I use this template (Xslt 1.0):

<xsl:template name="calcdays">
  <xsl:param name="date" />
  <xsl:variable name="year" select="substring($date,1,4)" />
  <xsl:variable name="month" select="substring($date,6,2)" />
  <xsl:variable name="day" select="substring($date,9,2)" />
  <xsl:value-of select="(($year - 1970) * 365) + floor(($year - 1969) div 4) + substring('000,031,059,090,120,151,181,212,243,273,304,334,365',($month * 4) - 3,3) + ($day - 1) + (1 - floor((($year mod 4) + 2) div 3))*floor(($month + 17) div 20)" />
  </xsl:template>
</xsl:stylesheet>

to determine the number of days since 1st Jan 1970, assuming the parameter passed in is in the form yyyy-mm-dd Any other form, you can tweak the substrings.

Call this template with the date strings and pass the results into variables, and you can do a straight comparison on $later - $earlier &lt;= 30.

Flynn1179
@Flynn1179: order comparison operators don't work with string data type in XSLT 1.0
Alejandro
It does if the values are just textual representations of numbers; I guess the translate is necessary in this case, although it's probably not a reliable mechanism for comparing dates, as it'll treat all months as having 100 days!
Flynn1179
@Flynn1179: It's not a reliable mechanism for difference calculation. It might be not realiable for comparison if the format will include time zone.
Alejandro
Do you mean the straight comparison, or the use of the template?
Flynn1179
@Flynn1179: I'm not talking about your named template, I didn't test. I'm talking about straight comparison after `fn:translate`
Alejandro
That's hardly relevant in this case, but yes, if you're dates have time zones, then you may need to account for that. In this instance, doing so would be needlessly complex, given that the time of day isn't used and is highly unlikely to have different timezones anyway, based on the information given.
Flynn1179