Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • manwood 87 posts 109 karma points
    Apr 04, 2010 @ 18:44
    manwood
    0

    Are there any library functions for comparing dates?

    I need an easy way of testing if a supplied date falls within a range in XSLT - how do you suggest I best achieve this?

    thanks

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 04, 2010 @ 22:24
    Douglas Robar
    1

    In the umbraco.library there are a number of date functions that'll help. Also some in the Exslt.DateTime library.

    In your xslt file, click the 'value of' icon in the toolbar. In the dialog that appears, click the 'extensions' button on the right of the window. Then select the library and you'll see a list of all the helper functions available. Lots of great gems in there!

    cheers,
    doug.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 9x admin c-trib
    Apr 04, 2010 @ 22:34
    Chriztian Steinmeier
    0

    Hi manwood,

    For the simplest stuff, you can make use of the fact that the way dates are stored in XML, they are sortable and comparable as plain text, e.g.:

    <xsl:if test="'2010-04-04T22:27:56+0200' &gt; '2010-04-01T12:00:00+0200'"> <!-- true() -->

    But for more advanced stuff, where you need to take different criteriae into account (timezones, "today", etc.) you should check out the following methods in the umbraco.library namespace:

    DateAdd()
    DateAddWithDateTimeObject()
    DateDiff()
    DateGreaterThan()
    DateGreaterThanOrEqual()
    DateGreaterThanOrEqualToday()
    DateGreaterThanToday()

    Also, the Exslt.DatesAndTimes namespace has some useful functions, whose names escape me at the moment.

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 9x admin c-trib
    Apr 04, 2010 @ 22:36
    Chriztian Steinmeier
    0

    Aargh... :-) too slow on the keys...

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies