PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $date = '2022-W10'; // 1. parce year & week from string preg_match('/(\d{4})-W(\d+)/', $date, $matches); $year = $matches[1]; $week_no = $matches[2]; printf('Year: %d, Week no.: %d' . PHP_EOL, $year, $week_no); // get date by year & week number $week_start = new DateTime(); $week_start->setISODate($year, $week_no); // get month $month = $week_start->format('n'); printf('Month: %d' . PHP_EOL, $month); // get quarter $quarter = ceil($month/3); printf('Quarter: %d' . PHP_EOL, $quarter);
Show:  
Copy Clear