I have a requirement to create a expiry date for the last Sunday of a year. I understand I could use strtotime
function to pass something like 'Last Sunday', can this be applied to the current year?
One way to do it:
echo "Last Sunday of 2013 is: ".date('Y-m-d', strtotime('01/01/2014'.' last Sunday'));
which will produce
Last Sunday of 2013 is: 2013-12-29
sandbox test for all days in a week
UPDATE: Code has been updated to solve the problem @hakre correctly pointed out. Anyway probably the proper way to go is the one that @Austin Brunkhorst suggested.
With strtotime
you can use 'last'
space
dayname
space
'of'
monthname
, which is relative to the current year:
strtotime('last sunday of december')
see Relative FormatsDocs for the formats available.