View Single Post
Old 06-16-2022, 08:33 PM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,071
Google is your friend.

https://rosettacode.org/wiki/Find_th...each_month#PHP

Like baodb said, you can use the string "last sunday of month year" in the date function to get the date of the last sunday.

date('Y-m-d', strtotime('last sunday of ' . $month . ' ' . $year)

Here is an example they have looping through and getting the last sunday of every month.

// Created with PHP 7.0

function printLastSundayOfAllMonth($year)
{
$months = array(
'January', 'February', 'March', 'April', 'June', 'July',
'August', 'September', 'October', 'November', 'December');

foreach ($months as $month) {
echo $month . ': ' . date('Y-m-d', strtotime('last sunday of ' . $month . ' ' . $year)) . "\n";
}
}

printLastSundayOfAllMonth($argv[1]);

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote