I have an array of random dates (not coming from MySQL). I need to group them by the week as Week1, Week2, and so on upto Week5.
What I have is this:
function weekOfMonth($strDate) { $dateArray = explode("-", $strDate); $date = new DateTime(); $date->setDate($dateArray[0], $dateArray[1], $dateArray[2]); return floor((date_format($date, 'j') - 1) / 7) + 1; }
weekOfMonth ('2015-09-17') // returns 3