Number of days between two dates - PHP

Number of days between two dates - PHP

how to find number of days between two dates in php

ยท

1 min read

Hi friend ๐Ÿ˜Ž

Do you know, how can you get number of days between two dates in PHP ?

In this blog post we are going to write a function to find number of days between two dates. I hope this can help you ๐Ÿ‘.

We can achieve this using the strtotime function.

strtotime function converts date into unix timestamp.

Please refer below code :

//$start_date is starting date
$start_date = '2020-01-25';

//$end_date is ending date
$end_date = '2020-02-20';

$starttotime  = strtotime($start_date);
$endtotime    = strtotime($end_date);

$days_between = ($endtotime - $starttotime)/86400;

//$days_between is number of days
ย