How to find the time elapsed since a date time with PHP?

Spread the love

Sometimes, we want to find the time elapsed since a date time with PHP.

In this article, we’ll look at how to find the time elapsed since a date time with PHP.

How to find the time elapsed since a date time with PHP?

To find the time elapsed since a date time with PHP, we can subtract times.

For instance, we write

$event_time = "2022-04-28 17:25:43";
$age = time() - strtotime($event_time);

to call strtotime with $event_time to convert it to a time object.

Then we subtract the current time that we get with time by it to get the elapsed time.

Conclusion

To find the time elapsed since a date time with PHP, we can subtract times.

Leave a Reply

Your email address will not be published.