We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24983
    • 59 Posts
    Hi I’m having a problem with the new 0.9.6 version that wasn’t in 0.9.5. The problem is that I have a snippet that I have called [[documentEditet]] that simply prints the date when the document was, you’ve guessed it, last edited.

    The code for the snipet is as follows, as in the example in the documentation (http://modxcms.com/document-tvs.html):

    <?php
    $date = $modx->documentObject[’editedon’];
    echo strftime("%d/%m/%y %H:%M:%S", $date);
    ?>

    The error I get is: "Error while inserting event log into database."
    I don’t get the error if I just echo $date without the strftime function, but then I will just get the timestamp and that is not very useful at all.

    Can someone please help me? Am I doing this the wrong way?
      • 24983
      • 59 Posts
      Ah forget it I found out what was wrong, MODx doesn’t like it when MySQL 5 is running in strict mode.
        • 4041
        • 788 Posts
        I have used this snippet for quite a while, and so far no kinds of errors.... does basically the same thing but has a little text format options smiley

        /*
          LastUpdated
          last edit:  7/26/06  3:52 pm est
          Usage: [!LastUpdated?dateformat=%B %e, %Y!] Returns date formatted: July 13, 2005
          See strftime() documentation for additional formatting options
        */
        // Default Date/Time format to use if not sent in snippet call
        $format = isset($dateformat) ? $dateformat : "%B %e, %Y";
        
        // added a message to show
        $update_pre ="<span class='smtxtblue'>This document was ";
        $update_suf ="</span>";
        $created_text ="created on ";
        $edited_text ="modified on ";
        
        
        $doc_created =  $modx->documentObject['createdon'];
        $doc_edited = $modx->documentObject['editedon'];
        
         if($doc_edited =="0"){
            $update_date = strftime($format,$doc_created);
            $update_text = $created_text;
           }else{
            $update_date = strftime($format,$doc_edited);
            $update_text = $edited_text;
           }
        
          
        $update = "$update_pre $update_text $update_date $update_suf";
        return $update;
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 24983
          • 59 Posts
          The way I did was creating a basic TV with the following default value:

          @EVAL return "Last updated ".strftime("%H:%M", $modx->documentObject[’editedon’])." on the ".strftime("%d/%m/%Y", $modx->documentObject[’editedon’]);

          Gives the following output: "Last updated 17:48 on the 27/05/2007"

          Anyways, thanks for the reply.