![]() |
Date() countdown until last Sunday of the month?
I have the following code:
Quote:
I've searched a few different places and can't find anything specific to what I need :( Hopefully that makes sense? TIA for any help you can offer. |
Did you try 'last Sunday of the month'? PHP surprisingly can parse a lot of these things and do the heavy lifting for you
|
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]); . |
I swear I searched for this in Google and Sitepoint and nothing came up :/
Thank you both. |
Really never came across strtotime??
|
All times are GMT -7. The time now is 08:53 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123