19
Feb
08

Comparing Dates in SharePoint Using XSL

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:

<xsl:value-of select=”ddwrt:Today()”>
(‘02/19/2008′ if your language is set to 1033)

You can also get the full ISO date and time with:

<xsl:value-of select=”ddwrt:TodayISO()”>
(‘2008-02-19T11:15:02Z’)

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’)”>
(‘20080219′)

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’) &lt;= ddwrt:FormatDateTime(string(@EventDate), 1033, ‘yyyyMMdd’)”>

Technorati tags: , , ,

Leave a Reply




 

February 2008
M T W T F S S
« Jan   Mar »
 123
45678910
11121314151617
18192021222324
2526272829  

Twitter Updates