Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

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);
Copy Clear