We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53178
    • 24 Posts
    Hi guys,

    Love modx as I am strong with frontend but weak with php (will fix that this year).

    Straight to my query, I am creating events and I have tvs for start date of event
    [[+tv.eventDate]]
    and End of event
    [[+tv.eventEndDate]]
    . I have it in a json like this
    {
    			"name": "[[+pagetitle]]",
    			"image": "[[+tv.eventCoverPage]]",
    			"day": "[[+tv.eventDate:strtotime:date=`%d`]]",
    			"month": "[[+tv.eventDate:strtotime:date=`%m`]]",
    			"year": "[[+tv.eventDate:strtotime:date=`%Y`]]",
    			"time": "[[+tv.eventDate:strtotime:date=`%R %P`]]",
    			"duration": "2",
    			"location": "[[+tv.eventLocation]]",
    			"description": [[+content:toStripJson]]
    		}
    


    What I want is to simply know the duration of the event by using the two tvs (tv.eventEndDate - tv_eventDate) that it can output to "duration" field above.

    For example the user selects start of event is 31st March 2017 and end of event is 2nd April 2017, it will be able to calculate that this is two days and output 2 to the "duration" of event field.

    My utmost appreciation in advance.

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      :date = `%j` will give you the day of the year (0 - 366), so (start - end) +1 should give you the duration in days unless the event spans two separate years.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 53178
        • 24 Posts
        Thank you BobRay you are the best.

        Though I changed it to (End-Start)+1 because if the end and start date is the same it returns 0 days and I want it to return 1 day, which is to say that the event is only for one day. If the end date is the next day I want it to return 2 days that is why I changed it.

        Thank you once again. Long live Modx

        Quote from: BobRay at Mar 09, 2017, 06:23 AM
        :date = `%j` will give you the day of the year (0 - 366), so (start - end) +1 should give you the duration in days unless the event spans two separate years.
          • 3749
          • 24,544 Posts
          I changed it to (End-Start)+1

          That's what I meant to write. wink

          I'm glad that worked for you.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting