What are the potential pitfalls of using floor() function in PHP for converting seconds to higher time units like weeks or months?
Using the floor() function to convert seconds to higher time units like weeks or months may not provide accurate results due to the varying lengths of months and the irregularity of leap years. To accurately convert seconds to weeks or months, it is better to use PHP's DateTime class along with DateInterval objects to handle the conversions correctly.
$seconds = 86400; // Number of seconds in a day
$interval = new DateInterval('PT' . $seconds . 'S');
$date = new DateTime('now');
$date->sub($interval);
$weeks = floor($date->format('z') / 7); // Convert to weeks
$months = floor($date->format('z') / 30.44); // Convert to months
echo "Weeks: $weeks, Months: $months";