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 15, 2013 @ 10:56
    Alexandru
    0

    DateDiff() parsing error

    Hello,

    After a few nightmare days of trying to figure out why my published blog won't run some of my macros, I have managed to isolate the problem and pinpoint the source of the errors.

    It's this guy over here:

    <xsl:variable name="diffSeconds" select="umbraco.library:DateDiff($currentDate, $postDate, 's')"/>
    

    which is part of this section that calculates the time since the current post has been published:

    <xsl:variable name="currentDate" select="umbraco.library:FormatDateTime(umbraco.library:CurrentDate(), 'dd-MM-yyyy')"/>
                    <xsl:variable name="postDate" select="umbraco.library:FormatDateTime(umbraco.library:LongDate($post/PostDate), 'dd-MM-yyyy')"/>
                    <xsl:variable name="diffSeconds" select="umbraco.library:DateDiff($currentDate, $postDate, 's')"/>
                    <xsl:variable name="diffDays" select="floor($diffSeconds div (60 * 60 * 24))"/>
    

    What the hell is really wrong with it, really? I had tried retyping it several times - letter by letter, still no luck.

    Strange thing is, it works on my local machine with no problem at all, and I can open both the local website and the published website one next to eachother and the online one won't run the macros that contain that module.

    I need some help, please

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 15, 2013 @ 11:09
    Chriztian Steinmeier
    0

    Hi Alexandru,

    If all the logic works fine on other machines I will bet you a beer that the problem site has a node somewhere with an empty PostDate property...

    Try putting an if statement around this logic to test for that, e.g.:

    <xsl:if test="normalize-space($post/PostDate)">
        <!-- logic from above -->
    </xsl:if>
    

    One other thing that may be able to trigger problems with stuff like this, is when the locales differ on the machines - date functions use Culture info and depending on the functions used they can generate differing output from locale to locale...

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Nov 15, 2013 @ 11:17
    Alexandru
    0

    Hi Chriztian,

    Thanks but it's not an empty PostDate property - I have just tried the if statement. :(

    Also, because of the way the logic is made, it formats all date variables using FormatDateTime() which means that regardless of the current date and the way it is displayed it should format it and prepare it for DateDiff().

    Am I right?

  • Alexandru 112 posts 272 karma points
    Nov 15, 2013 @ 11:23
    Alexandru
    0

    None of the PostDate properties may be empty as I have made them mandatory.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 15, 2013 @ 11:32
    Chriztian Steinmeier
    100

    Alright - guess I owe you a beer then :-)

    I think you will be better off not using FormatDateTime() before you need to display the date - all calculations should use the "native" date format, so you're not accidentally comparing to different formats.

    Did you check the locale settings? Are the machines set to different locales/languages?

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Nov 15, 2013 @ 11:44
    Alexandru
    0

    Lucky for you, I removed the Format date functions before any calculations (for all 3 macros that didn't work) and now they do work!!! - which means you don't owe me a beer anymore hehe. :)

    That's why I would get the same errors on a different user locally on the same computer, because the local date format was different.

    You have been of great help Chriztian, thank you so much!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 15, 2013 @ 11:53
    Chriztian Steinmeier
    0

    Phew :)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft