Cecatrix
Cecatrix

Reputation: 151

Date that will print the last day of the month plus additional 5 days

Hi currently I have a date that is printing the last day of the month for example this month is August, it will print August 31, 2017.

This is the code:

    $lastdate = date('F t, Y');
    echo $lastdate ;

My problem is I want it to print 5 additional days to the last day of the month, so for example rather than it will print August 31, 2017 it will print Septermber 5, 2017

Upvotes: 0

Views: 73

Answers (1)

John Conde
John Conde

Reputation: 219814

echo (new \DateTime('last day of this month'))->modify('+5 days')->format('F j, Y');
  1. Create a DateTime() object for the end of month
  2. Add 5 days to it
  3. Format the date

To do next month:

echo (new \DateTime('last day of next month'))->modify('+5 days')->format('F j, Y');

To do another month:

echo (new \DateTime('October 31, 2017'))->modify('+5 days')->format('F j, Y');

That should give you the idea.

Upvotes: 3

Related Questions