Is there a nice way to implement timeago with datatables?

Is there a nice way to implement timeago with datatables?

magepvp117magepvp117 Posts: 1Questions: 1Answers: 0

I currently have a datatable that stores timestamps. I would like to display this in the datatable in the "x seconds ago" format. Here is my table output.

 <table id="player_data" class="table table-bordered">
        <thead>
            <tr>
                <td>1</td>
                <td>2</td>
                <td>3</td>
                <td>4</td>
                <td>5</td>
                <td>Time</td>
            </tr>
        </thead>
         <?php
          while($row = mysqli_fetch_array($result))  
          {  
               echo '  
               <tr>  
                    <td>'.$row[ "1"]. '</td>  
                    <td>'.$row[ "2"]. '</td>  
                    <td>'.$row[ "3"]. '</td>  
                    <td>'.$row[ "4"]. '</td>  
                    <td>'.$row[ "5"]. '</td>  
                    <td>'.$row[ "time"]. '</td>
               </tr>  
               ';  
          }  
          ?>
</table>

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,872Questions: 1Answers: 10,527 Site admin
    edited March 2017 Answer ✓

    Quick point: You don't have a tbody element.

    Regarding timeago, seeing has you are generating the output from PHP you could use (time() - $row['time']).

    Allan

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Alternatively, use one of MySQL's date arithmetic functions to return your requirements.

  • allanallan Posts: 63,872Questions: 1Answers: 10,527 Site admin

    Which would probably be significant more performant. Good suggestion :smile:.

    Allan

This discussion has been closed.