Especially when you are using Data View Web Parts (DVWPs), but anytime you are using a Web Part that allows custom XLS to control display, you may want to do a test on dates. Doing this is relatively easy if you know a few of the ddwrt namespace date functions.
In this example, let’s say that you’d like to display calendar events that occur today or later. (Old calendar events aren’t of much use to display.)
The first step is to get today’s date. You can do this with the following XSL:
(’02/19/2008′ if your language is set to 1033)
You can also get the full ISO date and time with:
For comparison purposes, though, you’d like to have the date in YYYMMDD format. You can do this conversion with the FormatDateTime ddwrt function:
<xsl:value-of select="ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd')">
So, to compare your event date to today’s date, it’s a quick test:
<xsl:if test="ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') <= ddwrt:FormatDateTime(string(@EventDate), 1033, 'yyyyMMdd')">
If you found this post helpful, please consider visiting one or more of the advertisers on the page. Writing good, in depth blog posts takes time, and advertising revenue - though by no means large - helps to offset the effort.