Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?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);