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

    I would like to display some text on my blog page that basically says something like:

    3 hours, 24 minutes and 10 seconds since the last post.

    Wondering how I would achieve this, wouldn’t be a call from ditto?

    Thanks
    Lee
      http://www.blend.uk.com | Web Design by Blend
      • 18397
      • 3,250 Posts
      Ah, clever idea... A natural extension would be x days old posting thing...

      You would want to select the last document created by executing a SQL query sorted by createdon and limiting it to 1. Then use this function http://www.gidnetwork.com/b-16.html to get the information you want with time() as one parameter and the createdon date as the other. You can then use the output array to format to your liking.
        • 17717
        • 433 Posts
        Thanks Mark,

        I will have a go at that and let you know if I have any success.

        Thanks
        Lee
          http://www.blend.uk.com | Web Design by Blend
          • 17717
          • 433 Posts
          Couldn’t find it the downloads, anyone else know the name of the above?

          Thanks,
          Lee
            http://www.blend.uk.com | Web Design by Blend
            • 7455
            • 2,204 Posts
            you need to make you own snippet for this.

            There is no think like this yet.

              follow me on twitter: @dimmy01
              • 31037
              • 358 Posts
              Hi!

              I don’t know if this could be to any help, but here I go!

              I use this code on the demo site for PPP:

              <?php
              //Snippet phx:calcTime
              //Small PHx snippet to retrieve time since date.
              //Not very exact but could work as a sample
              //By Uncle68 - nov 2006
              
              $diff = (time()+20) - $output;
              
              $months = floor($diff/60/60/24/7/4);
              $days = floor($diff/60/60/24);
              $hours = floor($diff/60/60);
              $minutes = floor($diff/60);
              
              if ($days > 0) 
              {
              	$diff = $days . ' days';
              } 
              elseif ($hours > 0 && $hours < 60)
              {
              	$diff = $hours . ' hours';
              }
              else
              {
              	$diff = $minutes . ' minutes';
              }
              
              return $diff;
              ?>


              It is not very exact, but it could maybe help you get started.

              I call it with the help of phx, this is my call:

              [+phx:input=`[+placeholderWithUnixTime+]`:calcTime+]

              /Uncle68
                • 17717
                • 433 Posts
                Thanks for your help, i’ll give that a go.

                Thanks
                Lee
                  http://www.blend.uk.com | Web Design by Blend
                  • 14050
                  • 788 Posts
                  This might get you a little closer to what you were trying to do, although I threw this together quickly, so hopefully it doesn’t have any problems :-D You might want to add some extra conditionals to handle plural so you don’t end up with something like 1 days 1 hours 1 minutes, when you should have 1 day 1 hour 1 minute.

                  <?php
                  $table = $modx->getFullTableName("site_content");
                  $results = $modx->db->select("createdon", $table, "", "createdon DESC", "1");
                  $results = $modx->db->getRow($results);
                  $createdon = $results['createdon'];
                  $now = time();
                  $diff = $now - $createdon;
                  
                  $days = floor($diff/60/60/24);
                  $hours = floor($diff/60/60);
                  $minutes = floor($diff/60);
                  
                  if ($days > 0) 
                  {
                  	$output = $days . ' days ';
                      $diff = $diff - ($days * 86400);
                  	$hours = floor($diff/60/60);
                      
                  } 
                  
                  if ($hours > 0)
                  {
                  	$output .= $hours . ' hours';
                      $diff = $diff - ($hours * 3600);
                      $minutes = floor($diff/60);
                  }
                  if ($minutes >0)
                  {
                  	$output .= $minutes . ' minutes';
                  }
                  
                  return $output;
                  ?>
                    Jesse R.
                    Consider trying something new and extraordinary.
                    Illinois Wine

                    Have you considered donating to MODx lately?
                    Donate now. Every contribution helps.
                    • 33337
                    • 3,975 Posts
                    Or may be using:
                    1 day(s) 1 hour(s) 1 minute(s) ? tongue
                      Zaigham R - MODX Professional | Skype | Email | Twitter

                      Digging the interwebs for #MODX gems and bringing it to you. modx.link
                      • 14050
                      • 788 Posts
                      Lazy... tongue
                        Jesse R.
                        Consider trying something new and extraordinary.
                        Illinois Wine

                        Have you considered donating to MODx lately?
                        Donate now. Every contribution helps.