What is the XSLT query to get items which have date greater than or equal today
-
07-01-2021 - |
Question
I haven't worked on XSL.
Scenario: We have a list which has a column called expiry. We want to display only those records which have expiry date greater than or equal to today's date.
Trials: After n number if trials and googling have found out how to set a XSL variable today's date
<xsl:variable name="curDt" select="ddwrt:Today()"/>
In this link got a way to apply filter on date column. However it is not working.
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[number(translate(substring-before(@Date,'T'),'-','')) >= number(translate($curDt,'-',''))]"/>
Kindly let know to apply this filter
Solution
Got this working using below query
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[number(ddwrt:FormatDateTime(ddwrt:FormatDate(string(@Date),1033,1),
1033,'yyyyMMdd'))>=number(ddwrt:FormatDateTime(ddwrt:FormatDate(string($curDt),1033,1),1033,'yyyyMMdd'))]"/>
$curDt
is a xsl variable
It has been set to Today's date as per XSL function
The resultant values of the above ddwrt and other functions is
yyyyMMdd >= yyyyMMdd
That is if suppose todays date is 26 Dec 2017 and current list item Date value is 29 Dec 2017 the values will be;
20171229 >=20171226
Following the approach of yyyyMMdd will always yield a current number value of date comparison