Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get next to next monday in PHP

Tags:

date

php

How can i get 2nd monday after the input date? i have solution but that not feasible

$date = new DateTime();
$date->modify('next monday');
$next_monday = $date->format('Y-m-d');
$date = new DateTime($next_monday);
$date->modify('next monday');
$next_monday = $date->format('Y-m-d');

Please suggest me some method to do so.

like image 418
ma_dev_15 Avatar asked Feb 15 '17 18:02

ma_dev_15


People also ask

How to get next date in PHP with examples?

Let’s dive into the following step by step approach to learn How to Get Next Date in PHP with examples: 1. PHP add 1 day to current date Note: Current Server Date was: 30 January 2022 when calculating tomorrow using above code

How to get 2021-12-01 date using PHP?

<?php $date = "2021-12-01"; $new_date = date ('Y-m-d', strtotime ($date. ' + 1 months')); echo $new_date; ?> Next Article How to Get Previous Month Date using PHP?

How to get the day of the week in PHP?

The PHP documentation for time () shows an example of how you can get a date one week out. You can modify this to instead go into a loop that iterates a maximum of 7 times, get the timestamp each time, get the corresponding date, and from that get the day of the week.

How do I get the first day of next month?

Get the first day of next month. Here, we get the first day of next month (relative to today’s date): Get next Thursday. Get the first Monday in January. If we need to get the first Monday in January: Obviously, you will need to change 2015 to match the year that is relevant to your requirements.


1 Answers

Your DateTime object's modify method takes the same type of arguments that strtotime does. You're already using 'next monday', you just need to use 'second monday' instead.

$date->modify('second monday');
echo $date->format('Y-m-d');

Also, in case you didn't know this, some of the DateTime methods can be chained:

echo $date->modify('second monday')->format('Y-m-d');
like image 52
Don't Panic Avatar answered Oct 05 '22 06:10

Don't Panic