Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,567 questions

14,363 answers

573 users

How to calculate the total weeks between two dates in PHP

2 Answers

0 votes
function total_week_between_two_dates($dt1, $dt2) {
    $datetimeobject1 = DateTime::createFromFormat('m/d/Y', $dt1);
    $datetimeobject2 = DateTime::createFromFormat('m/d/Y', $dt2);
    
    if ($dt1 > $dt2) {
        return total_week_between_two_dates($dt2, $dt1);
    }
    
    return floor($datetimeobject1->diff($datetimeobject2)->days/7);
}

$dt1 = '1/1/2019';
$dt2 = '3/12/2019';

echo total_week_between_two_dates($dt1, $dt2);

 
/*
run:
      
10
     
*/

 




answered Mar 12 by avibootz
0 votes
function total_week_between_two_dates($dt1, $dt2) {
    $date1 = new DateTime($dt1);
    $date2 = new DateTime($dt2);

    $interval = $date1->diff($date2);

    return floor(($interval->days) / 7);
}

$dt1 = '1/1/2019';
$dt2 = '3/12/2019';

echo total_week_between_two_dates($dt1, $dt2);

 
/*
run:
      
10
     
*/

 




answered Mar 12 by avibootz
...