Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 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, 2019 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, 2019 by avibootz

Related questions

...