Copied to clipboard

Flag this post as spam?

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


  • Alexandru 112 posts 272 karma points
    Nov 18, 2013 @ 11:39
    Alexandru
    0

    Convert date to number

    Hello,

    I am trying to prevent my blog from showing posts from the future in the archive by comparing the date folder name which is already converted to a number to the year part of the current date.

    How can I convert the year of the current date to a number?

    I have tried FormatDateTime with yyyy and then cast to number but it didn't work. Any ideas?

    I have managed to prevent future posts to show up on the homepage but this one is different.

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 18, 2013 @ 12:02
    Fuji Kusaka
    0

    Hi Alexandru

    Have you try something like

    <xsl:value-of select="umbraco.library:FormatDateTime(@createDate, 'dd MMMM, yyyy')" disable-output-escaping="yes"/>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 18, 2013 @ 12:03
    Chriztian Steinmeier
    0

    Hi Alexandru,

    You could probably make use of one of the date-compare functions, e.g.: DateGreaterThanOrEqualToday() or similar... that way you're using the actual date of the post(s) and not depending on them being in a correctly-named datefolder (even if that is automatically created).

    E.g., to make sure you're not selecting any future posts, start by creating a currentPosts variable:

    <xsl:variable name="currentPosts" select="$siteRoot//Event[not(umbraco.library:DateGreaterThanToday(pubDate))]" />
    

    and later base all other filtering on that one, e.g.:

    <xsl:for-each select="$currentPosts[author = 'James Bond']">
        <!-- Do something -->
    </xsl:for-each>
    

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 18, 2013 @ 12:07
    Chriztian Steinmeier
    101

    Oh - but to answer your real question, this should give you a number:

    <xsl:variable name="currentYearAsNumber" select="number(substring(umbraco.library:CurrentDate(), 1, 4))" />
    

    (It depends, I know, but you hardly ever need to do this in XSLT...)

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Nov 18, 2013 @ 12:27
    Alexandru
    0

    Thanks for the reply guys!

    Problem solved :D

Please Sign in or register to post replies

Write your reply to:

Draft