We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13695
    • 15 Posts
    Hi, I was wondering if there was a way to format a calculation of ’Months Remaining’ by subtracting one date entry from another, based on the current date, so for example:

    Two ’Date’ TVs:
    Start Date of Contract [*shareStartDate*]
    End Date of Contract [*shareEndDate*]

    Using an expression something like the one below, which works with basic numbers, just not a date:

    MONTHS OF CONTRACT REMAINING:
    [+phx:math=`[*shareStartDate:date=`%m`*]-[*shareEndDate%m:date=`%m`*]`+]

    Thanks!

    J
      • 16895
      • 87 Posts
      If you format the date to unixtime, do the subtratction, and then convert it back again it might work. Haven’t tried though.

      You might need to write a custom PHx snippet to do this; I’m sure Google will turn up PHP code for doing this pretty quickly.
        • 13695
        • 15 Posts
        I did a bit of a search but I’m pretty basic when it comes to PHP, I thought if there was a straight-forward way to do it I could probably do it...oh well.. I told them to get a real programmer not a designer to do it! ;o)
          • 16895
          • 87 Posts
          OK, sorry I couldn’t help there.

          By the way: if your programmer does come up with a nice neat PHx snippet for doing it, it might be helpful to other people like you in the future if you posted it back here.

          Thanks.
            • 26931
            • 2,314 Posts
            maybe this helps: CountDown Snippet ( google translate ):
            http://translate.google.com/translate?js=y&prev=_t&hl=en&ie=UTF-8&layout=1&eotf=1&u=http%3A%2F%2Fmodx.liolion.net%2Fresource%2Fcountdown.html&sl=ja&tl=en

            site: http://modx.liolion.net/resource/countdown.html
              • 13695
              • 15 Posts
              Greats stuff, thanks, that might just work....!