0

So I have a datetime string, and I want it to have an output that's human readable that says how long until that time comes up. So far, I have it saying days, but I'd also like this function that if it's less than a day, it will say how many hours from now, and if it's less than an hour, it will say how many minutes from now.

Right now, I have:

function days_until($date){
  $days_from_now = (isset($date)) ? floor((strtotime($date) - time())/60/60/24) : FALSE;
  return $days_from_now.' Days From Now';
}    

But what I noticed is that it will return with 0 days from now if it's already that day.

Josh Holly
  • 27
  • 1
  • 5
  • 3
    Handy function: [`diff`](https://www.php.net/manual/en/datetime.diff). – El_Vanja Apr 28 '21 at 21:49
  • 1
    Related to @El_Vanja, see this https://stackoverflow.com/a/5906737/231316 – Chris Haas Apr 28 '21 at 21:49
  • If you want it to be smarter and change the string depending on how long ago (like they do it here on stack overflow), then you can check out some library, like [Carbon](https://carbon.nesbot.com/docs/). – M. Eriksson Apr 28 '21 at 21:55

0 Answers0