Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Dec 18, 2009 @ 10:58
    Lee
    0

    Using Dates In XSLT?

    Yes me again :) ...  I'm needing to select nodes based on a date - The user can select a date and I want to show nodes(Events) up to the date specified.

    I was thinking the below .. But for some reason a voice in my head is telling me "I don't think its correct when you are using dates" ??  Is this the right way to do it?

    umbraco.library:FormatDateTime(./data [@alias='eventDate'], 'dd MMMM yy') <= umbraco.library:FormatDateTime($thedateselected, 'dd MMMM yy')

    Any advice greatly appreciated

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Dec 18, 2009 @ 11:28
    Douglas Robar
    1

    Lee, Lee, Lee... Spend an hour looking over the umbraco.library functions as well as the Exslt functions available. Tons of stuff for date handling, among other things. Knowing what utils are available will save you gads of time.

    In this case, maybe this is the function you want...

    umbraco.library:DateGreaterThanOrEqual(stringFirstDate, stringSecondDate)

     

    (Not trying to be sarcastic here, but I didn't spend the time learning the util functions early on and wasted a lot of time because of it. I'm legitimately trying to be helpful and recommend you NOT repeat my mistake. Okay? Okay.)

     

    cheers,
    doug.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 18, 2009 @ 12:11
    Lee Kelleher
    0

    Wise words from Doug - DateGreaterThanOrEqual is the way to go!

    If you are wondering what the problem with comparing the results from FormatDateTime, it's due to both values being strings (not dates, nor numeric) - so the XSLT/XPath can't compare them (using the less-than / greater-than operators).

    ...

    Lee, another thought is that since you've been clashing horns with XSLT a lot recently, you might want to go down the C# (API) route - see how that works out for you?  Obviously, I'm a massive fan of XSLT - it serves me well, but I recognise that it's not well-suited to everyone.

    Read Aaron Powell's blog post about "Why I'm not a fan of XSLT" - there are many alternative ways to achieve results using Umbraco!

    Good luck, Lee.

  • Lee 1130 posts 3088 karma points
    Dec 18, 2009 @ 12:30
    Lee
    0

    Hey Chaps, thanks again for posting with help :)

    I am already using the  DateGreaterThanOrEqual function in my query, but I couldn't find a DateLessThanOrEqual??  Which is why I went down the above route?

    The problem is I need to get nodes up to/before a certain date not after??  So am I right in thinking this is not the right method to use??

    @Doug - Thanks Doug, always appreciate your advice :) ... And to be honest I did/do look through the WIki but all the wiki pages are blank I tried to look at?  So people like me have no idea what the heck they do, so have to post multiple pleading posts on the forum (lol) :(

    http://our.umbraco.org/wiki/reference/umbracolibrary/dategreaterthanorequal

    @Lee - I definitely owe you a beer along with Doug @ Codegarden for the help/advice, I have read that post before and do use the API (And slowly getting my head round it) but on this occasion I am using Tims locator package and trying to extend/modify it and the way it works is all in his XSLT file so I'm a bit stuffed :(

  • Lee 1130 posts 3088 karma points
    Dec 18, 2009 @ 13:33
    Lee
    0

    Got to love the old forum still... I searched for 'Umbraco DateLessThanOrEqual' in Google and this thread came up

    http://forum.umbraco.org/yaf_postst2756p2_Select-a-node-depending-on-the-Day-of-the-Week-and-Time-of-Day.aspx

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 18, 2009 @ 14:23
    Lee Kelleher
    0

    Quickie, before I head off for lunch ... DateLessThanOrEqual? Try swapping the parameters around in the DateGreaterThanOrEqual?

    As one of the dates must be greater than the other... so the other is less than the first ... (I've gone cross-eyed!) ;-P

Please Sign in or register to post replies

Write your reply to:

Draft