The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Changing date format in cart (2.0)

flinx777flinx777 Member
in Help edited June 2015
Is it possible to change the date format in the cart on Foxycart 2.0?

http://files.smashstack.com/18RbB/h9rcRqKA

The client wants this format instead: 06-16-2015. We were able to write some jQuery that changed the Contract End Date but could not change the Subscription dates. We even tried to change the date format in the admin in the language section (http://files.smashstack.com/1kibf/3CmLu6DJ) which didn't work.
Comments
  • fc_jedfc_jed FoxyCart Team
    @flinx777

    Yes, it's possible.You're wanting to format the subscription dates in the cart listing, which you would do from the "Cart Include" template in your store's FoxyCart administration. Once you have that page open, select "custom" for the template, and search for the string "sub_startdate". There will be one result that looks like this:
    <span class="fc-cart__item__option__value">{{ item.sub_startdate }}</span>
    To format the date like "06-16-2015", you would need to add the Twig filter of 'date("m-d-Y")', so the above line would look like this:
    <span class="fc-cart__item__option__value">{{ item.sub_startdate|date("m-d-Y") }}</span>
    You can find more information about date formatting here: http://twig.sensiolabs.org/doc/filters/date.html

    As an aside, for what it's worth the international formatting for a date is YYYY-MM-DD, which is what we format the strings as by default. The main difference in formatting dates between countries is some display them as DD-MM-YYYY and others MM-DD-YYYY.
  • brettbrett FoxyCart Team
    @flinx777, I'm not sure what your relationship with the client is, but I'd push back on this one if it were me. Starting with the year is the only immediately obvious and unambiguous way to format dates, and once you modify the default cart template, you'll have more difficulty upgrading and such.

  • Would it be possible for reformat the date with abbreviated months? Or would this require some javascript?

    (e.g., Nov 1, 2016)

    Thanks.
  • fc_romanfc_roman Member, FoxyCart Team
    @Epotratz,
    Would it be possible for reformat the date … e.g., Nov 1, 2016
    Yes, you could add a filter to the dates in the cart include.

    For example, {{ item.sub_startdate}} would become {{ item.sub_startdate|date("M j, Y") }}. PHP date format options should work fine.
Sign In or Register to comment.