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.
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
<?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?
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.
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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With