3v4l.org

run code in 300+ PHP versions simultaneously
<?php function datediffInWeeks($date1, $date2) { if($date1 > $date2) return datediffInWeeks($date2, $date1); $first = DateTime::createFromFormat('Y-m-d', $date1); $second = DateTime::createFromFormat('Y-m-d', $date2); return floor($first->diff($second)->days/7); } echo datediffInWeeks('2021-10-13', '2020-10-01');// 21
based on jAYZd
Output for 7.3.0 - 7.3.27, 7.4.0 - 7.4.15, 8.0.0 - 8.0.2
53