I am new to PHP so I have an issue with how to check given date is available next month or not
$startEventDate = "2021-03-31";
I am new to PHP so I have an issue with how to check given date is available next month or not
$startEventDate = "2021-03-31";
I don't understand your question completely, but in my guess, you are looking for this
<?php
//Get the next month and year like this
$startEventDate = date("2021-03-01");
$newDate = strtotime ( '+1 month' , strtotime ( $startEventDate ) ) ;
$nextMonthYear = date('Y', $newDate);
$nextMonth = date('m', $newDate);
$nextmonthdate = date($nextMonthYear."-".$nextMonth."-31"); // append your date to the next month and year
Now you can test if the $nextmonthdate
is valid. There is a lot of ways to do that.
If you want to check if the selected date falls between a start and end date, you can do something like: (PHP 5 >= 5.2.0, PHP 7, PHP 8)
$startEventDate = new DateTime('2021-03-31');
$start = new DateTime();
$end = new DateTime();
$end->modify('+1 month'); // 1 month from today
if ($startEventDate > $start && $startEventDate <= $end) {
$result = 'avaialble';
} else {
$result = 'not avaialble';
}
echo sprintf(
'The selected date %s is %s between %s and %s',
$startEventDate->format('Y-m-d'),
$result,
$start->format('Y-m-d'),
$end->format('Y-m-d')
);
More specific to your question:
check given date is available in next month or not.
You can modify the code like
$startEventDate = new DateTime('2021-03-31');
$start = new DateTime('first day of next month');
$end = new DateTime('last day of next month');
....