Home > OS >  Total Days between two dates
Total Days between two dates

Time:10-30

i am beginner at php. I want to calculate exact total number of days between two dates using php, mysql and want to show it in html form. I tried datediff but it doesn't works as it gives , diffrence not total number of days.

Date fm - 10-10-22; Date to - 20-10-22; Total Days - 11

CodePudding user response:

add 1 to date_diff the output will 11 be like :

<?php
$d1=date_create("2022-10-10");
$d2=date_create("2022-10-20");
$diff=date_diff($d1,$d2);
echo $result = 1   $diff->format("%R%a days");
?>

CodePudding user response:

php has inbuilt DateTime functions to get the difference. Below outputs 10 day difference.

$date = new DateTime('2022-10-20');
$next_date = new DateTime('2022-10-30');
echo $date->diff($next_date)->days;
  • Related