We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    This is an auto-generated support/comment thread for SiteLastUpdated.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Display the date of the latest update to the entire site.
      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
      • 25046
      • 194 Posts
      I’ve tried this and it is exactly what I have been looking for. However, the date that is displayed is wrong. For example, it shows that the site was last updated at 8:35pm today but it is only 2:35pm.

      I have set the server offset time in ModX to -7 and the time is right in the Configuration settings.

      Any suggestions? thanks!
        • 25046
        • 194 Posts
        Also, it seems that the date provided through this snippet does not change, even though I may update it during the day. It seems to be locked (in my case at 8:10pm).

        Thanks
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          As far as the date not changing, is the snippet called uncached [!...!]?
            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
            • 25046
            • 194 Posts
            Thanks. Yes, here is the snippet call:

            [!SiteLastUpdated? &dateFormat=`F j, Y g:i A`!]

            This snippet call is part of a footer chunk that I am using for all of my pages. I suppose that the caching for the page is what takes precedence so maybe that’s why it’s not changing. Oh well, I can live with that. Thanks.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              No. If the snippet is called uncached, then it should always be processed. I actually have not used this snippet; I tested it and it seemed to work, but it appears that there is something wrong when it’s actually under load. I’ll put it on my site and watch it.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I think I see where the problem lies. Take as an example my situation with my server. I’m in Israel, my server is in California. There is a +10 hour time difference. So I have my server offset set to +10. The correct local time is displayed for Manager functions, and would also be a useful field to use for correcting the time for local viewers.

                I made a change to a document just now, and it’s not showing through the snippet’s date output, but that’s because while it’s the 16th here, it’s still only 10:30 on the 15th there. So to a viewer in California, it still has been last updated on the 15th, but from New York, or here in Israel, it looks like it wasn’t updated today at all.

                If I add the 10 hour offset to the snippet, it will correct things for local viewers, but the California viewer might be somewhat confused, seeing that it’s been updated on the 16th, when it’s still only the 15th there.
                  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
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Ok, here’s a version with a bit of javascript to detect the client’s localtime and convert the server’s time. If the client doesn’t have javascript enabled, it will show GMT/UTC.
                  <?php
                  $servertime = $modx->db->getValue($modx->db->select('editedon', $modx->getFullTableName('site_content'), 'published=1', 'editedon DESC', 1));
                  // to display if there's no javascript
                  // it actually always gets displayed but is replaced by the javascript.
                  $output = '<span id="lastModified">' . gmdate('d M Y H:i:s', $servertime) . '</span>';
                  // javascript uses milliseconds, so convert the Unix timestamp
                  $millitime = $servertime * 1000;
                  $output .= '<script type="text/javascript">
                  var d = new Date();
                  d.setTime('.$millitime.');
                  document.getElementById("lastModified").innerHTML = d.toLocaleString();
                  </script>';
                  
                  return $output;
                  ?>

                  Please don’t ask me how to configure the output, this took me three hours to figure out as it is; I am not a Javascript guru-ess by any means tongue
                    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