0

I have a code for days interval

<?php 
    $datetime1 = new DateTime(); // Today's Date/Time  
   $datetime2 = new DateTime('2012-07-17 15:30:17'); 
   $interval = $datetime1->diff($datetime2); 
   echo $interval->format('%D days %H hours %I minutes ago'); 
?>

How can I include time from database example

<?php echo htmlentities($row['date']); ?>
kenfire
  • 1,305
  • 12
  • 23
Adeola Web
  • 11
  • 2
  • Assuming you get an epoch time back from the database, you use that to create a PHP date of some sort: https://stackoverflow.com/q/13477788/1531971 –  Aug 29 '17 at 15:18
  • What type of column is `date`? If you get a string of `2017-08-29 17:25:10` back, then you can just do `$datetime2 = new DateTime($row['date']);`. – Qirel Aug 29 '17 at 15:26
  • Also, probably reference this topic: https://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago – Qirel Aug 29 '17 at 15:26
  • @Qirel the column in date is 2017/08/29 – Adeola Web Aug 29 '17 at 15:34

1 Answers1

1

I know you're using PHP, but if you want this on the front end you could consider moment.js: https://momentjs.com/ it handles human-like date outputs.''

Edit: after further searching, this is exactly what you're looking for momentPHP: https://github.com/fightbulc/moment.php

Moshe
  • 2,583
  • 4
  • 27
  • 70