We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19229
    • 3 Posts
    I would like help with Modx’s date formatting.

    On my system, every document’s created date, edited date, and published date are shown in month, day, year format (dd/mm/yyyy). I would prefer month, day, year (mm/dd/yyyy).

    Have I overlooked something in the installation or configuration that controls this? I am trying to learn ModX, and digging my way through the documentation, wikis and forum postings, but cannot seem to find a way to change this.



    Thanks for any help,


    - mike



    Basic installation details:


    Hosting (in the US)
    Apache Host (1.3.37)
    Php 5 (5.2.2) CGI
    Linux

    Database
    MySQL 5 (5.1.16)
    No large tables

    ModX
    Modx Version 0.9.6

    Changes to the default installation:
    - Added a few documents, a new template, and a few chunks.
    - Turned off quick edit.

    Browser & Client
    Windows XP
    Firefox version 2.0.0.6


    Configuaration Parmaters

    English
    Character encoding UTF-8
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Check the /manager/actions/document.data.static.php and mutate.document.dynamic.php files. These have code using the strftime() function to format and display the timestamp from the database, for example:

          <td><?php echo strftime("%d/%m/%y %H:%M:%S", $content['createdon']+$server_offset_time); ?> (<b><?php echo $createdbyname ?></b>)</td>
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 19229
        • 3 Posts
        Thank you.

        I found and edited /manager/actions/document.data.static.php. Works great.

        Just to confirm, it looks like the code in the above file is responsible only for displaying the page data, including the create, edit, publish and unpublish dates, but does not affect the way the dates are stored in the database. Is that correct?

        Could not find mutate.document.dynamic.php in /manager/actions ... did I misunderstand where it is located? What does this file do?



        Thanks again for your help.


        - mike





          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Sorry, it’s /manager/actions/mutate_content.dynamic.php, and it’s the script that lets you edit/create the documents. The publish/unpublish timestamps are set and edited there, and the "edited_on" timestamp is also set from that.
                          <td><input name="pub_date" value="<?php echo $content['pub_date']=="0" || !isset($content['pub_date']) ? "" : strftime("%d-%m-%Y %H:%M:%S", $content['pub_date']);?>" onblur="documentDirty=true;" />
          

          The various dates (create, edit, publish, unpublish) are stored as UNIX timestamps in the database, which is exactly what the UNIX timestamp was created for 30 or so years ago. It is an integer value that reflects the number of seconds from the beginning of the "UNIX epoch" back in 1970 or something like that, and there are a number of PHP functions for working with it; strftime() (the user comments at the bottom of this page are well worth reading) is one of these for displaying it in useful formats. It’s not good for things like people’s birthdays or calender scripts, but it is great for using as a "timestamp" the creation or other management for electronic documents, since there simply weren’t any before 1970. Its being an integer value makes for compact storage in the database, but it will be a problem in 2038 or something like that when it gets too big (too many seconds from 1970), but like the "year 2000" issues, that will have to be dealt with sometime in the next 30 years.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 19229
            • 3 Posts
            Thank you, Ms. Ottwell.

            This change is a bit more complex. The validation routine for the popup calendar will need to be changed, too. I’ll dig into it.

            Is there any consideration to make the date format conform to local custom in a future release? I know the US is out of step, but we like our dates to be formatted as mm/dd/yyyy ... ;-)

            Thanks again for your help!



            - mike