This project is read-only.

XSLT Extension - Dates

The Dates library XSLT extension can be used to present your dates in various ways.

Enabling the XSLT extension for use in your XSLT templates.

Add the following XML snippet to your ~/config/xsltExtensions.config file:

<XsltExtensions>
	...
	<ext assembly="uComponents.Core" type="uComponents.Core.XsltExtensions.Dates" alias="ucomponents.dates" />
	...
</XsltExtensions>

Methods

Here are available methods:

Method Returns Notes
AddWorkdays(String, Int32) Adds the workdays, excluding weekends.
AddWorkdays(String, Int32, String) Adds the workdays, excluding weekends.
Age(String) Returns the age based on the specified date of birth. Get the current age, from the specified date of birth.
DateWithinLastDays(String, Int32) Returns true or false depending on if the date is within the last number of days. Tests if a date is within the last number of specified days.
ElapsedSeconds(String) Returns the elapsed seconds since the input DateTime. Gets the elapsed seconds since the input DateTime.
FormatDateTime(DateTime, String) Formats the date time.
FormatDateTime(String, String) The formated date string Converts the value of the date time string to its equivalent string representation using the specified format.
GetDayNumberSuffix(DateTime) The ordinal suffix Gets the ordinal suffix for a given date
GetFirstDayOfMonth(String) Gets the first day of month.
GetFirstDayOfMonth(String, String) Gets the first day of month.
GetLastDayOfMonth(String) Gets the last day of month.
GetLastDayOfMonth(String, String) Gets the last day of month.
GetPrettyDate(String) Returns a pretty date. Gets the pretty date.
GetPrettyDate(String, String) Returns a pretty date. Gets the pretty date.
IsLeapYear(String) true if (is leap year) (the specified date); otherwise, false. Determines whether (is leap year) (the specified date).
IsWeekday(DayOfWeek) true if the specified day is weekday; otherwise, false. Determines whether the specified day is weekday.
IsWeekday(String) true if the specified date is weekday; otherwise, false. Determines whether the specified date is weekday.
IsWeekend(String) true if the specified date is weekend; otherwise, false. Determines whether the specified date is weekend.
ListDates(string startDate, string endDate) Returns a nodeset of all the dates between the start and end date. Lists all the dates between the start and end dates.
ToUnixTime(String) Return the total number of seconds between Unix epoch and the specified date/time. Converts a date to Unix time.
WorkdaysDiff(string startDate, string endDate) Returns the number of workdays between two dates. Gets the number of workdays between two dates.

Usage examples

Here are some example XSLT snippets to show you how.

FormatDateTime(string date, string format)

<p>
	FormatDateTime (Regular): <xsl:value-of select="ucomponents.dates:FormatDateTime('2010-09-21', 'dd MMMM yyyy')"/>
</p>

<p>
	FormatDateTime (With suffix): <xsl:value-of select="ucomponents.dates:FormatDateTime('2010-09-22', 'ddS MMMM yyyy')"/>
</p>

<p>
	FormatDateTime (Escaped suffix token): <xsl:value-of select="ucomponents.dates:FormatDateTime('2010-09-23', 'dd\S MMMM yyyy')"/>
</p>

Download example XSLT: FormatDateTime.xslt

GetPrettyDate(string date, [optional] string format)

<dl>
	<xsl:for-each select="$currentPage/*[@nodeName]">
		<dt>
			<xsl:value-of select="@nodeName" />
		</dt>
		<dd>
			Last updated:
			<xsl:value-of select="ucomponents.dates:GetPrettyDate(@updateDate, 'ddS MMMM yyyy')" />
		</dd>
	</xsl:for-each>
</dl>

Download example XSLT: GetPrettyDate.xslt

Last edited Jun 30, 2011 at 9:14 PM by leekelleher, version 6