Copied to clipboard

Flag this post as spam?

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


  • Eric 12 posts 32 karma points
    Nov 26, 2012 @ 22:20
    Eric
    0

    Testing if created date of a node is within a certain range

    I want to test to see if a node was created within 2 weeks (14 days) of the current date. Is there any way to test if created dates are within a specific range? 

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 26, 2012 @ 22:31
    Chriztian Steinmeier
    0

    Hi Eric - welcome to the forum!

    Yes - there are a couple of useful extensions for this, e.g.: DateGreaterThanOrEqual() in the standard extension library for Umbraco.

    Only tricky bit is doing the DateDiff duration... I'll see if I can cook up an example for you - but have look at the above first.

    /Chriztian 

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 26, 2012 @ 22:45
    Chriztian Steinmeier
    0

    Hi again,

    You should be able to test that with the following:

    <xsl:variable name="secondsInADay" select="60 * 60 * 24" />
    
    <!-- Grab the year, month and date for today -->
    <xsl:variable name="today" select="substring-before(umbraco.library:CurrentDate(), 'T')" />
    
    <!-- Do the date/math stuff -->
    <xsl:variable name="daysSinceCreated" select="umbraco.library:DateDiff($today, substring-before($currentPage/@createDate, 'T'), 's') div $secondsInADay" />
    
    <xsl:if test="$daysSinceCreated &lt;= 14">
        <p>New content this is</p>
    </xsl:if>

     

    /Chriztian

  • Eric 12 posts 32 karma points
    Nov 26, 2012 @ 23:12
    Eric
    0

    Thank you so much! That's exactly what I was looking for. I really appreciate your time and super quick responses!!!

  • 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