Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 08, 2012 @ 19:57
    Bjarne Fyrstenborg
    0

    Difference between dates

    Hi..

    If there another way to get the difference between two dates in days than using DateDiff ?

    It seems only to have the parametres: "s", "m" or "y" so I have to set the 14 days in minutes:

    <xsl:variable name="currentDate" select="umbraco.library:CurrentDate()"/>
    <xsl:variable name="created" select="$product/@createDate"/>

    <
    xsl:if test="umbraco.library:DateDiff($currentDate, $created, 'm') &lt;= 20160">
       <img src="/gfx/new_sticker.png" alt="" width="94" height="85" class="new_sticker" />
    </xsl:if>
    <xsl:if test="oldPrice != ''">
       <img src="/gfx/offer_sticker.png" alt="" width="94" height="85" class="offer_sticker" />
    </xsl:if>

    Bjarne

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 08, 2012 @ 20:10
    Tom Fulton
    0

    Hi Bjarne,

    That's strange, can you not use "d" for days?  I thought you'd be able to use any of the intervals documented here.

    -Tom

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 08, 2012 @ 20:27
    Bjarne Fyrstenborg
    0

    Yes, that's strange.. if I use d instead of m it just return 0 on every product.

    When I use m for minutes it return numbers like: 50143, 12569, 12568... and so on..

    So it doesn't seem to be an available parameter in that method..

    Bjarne

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 08, 2012 @ 20:41
    Tom Fulton
    0

    Ah you're right, confirmed it in the source.  Very strange indeed!  Not sure why it's done that way...

    If you wanted you could look into uComponents Dates extensions, it has DateWithinLastDays(string, int) that returns true/false.  Or if you're just looking to improve readability, you could of course create a variable called $numDays and just multiply by 24 * 60  in your DateDiff call.

    -Tom

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 08, 2012 @ 20:50
    Bjarne Fyrstenborg
    0

    Yes very.. it's a common scenario where you want to use dates.. but of course I can just multiple number of days with 24*60 ..

    Thanks, that might be useful.. but in this case it's okay with that fix..

    Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft