I have a string with the value in the format below
10:00 AM, 31 January 2017
The first task my client assigned me was to find January in that string which I have succeeded using the code below
<?php
$season_date = "10:00 AM, 31 January 2017";
if(strpos($season_date, 'January') !== false ) {
echo "True"; // Apply price increase percentage
}
?>
Now he has extended the task to find dates range for eg:
20 January - 02 February
How do I go about in doing this?
Edited:
I just realized my problem is bigger than the above. I actually have 2 dates
$start->format('g:i A, d F Y'); and $end->format('g:i A, d F Y');
So it's not just the matter of finding the specified string within the start and end dates, but also in between. Argh.
My final code. Thanks to everyone :)
<?php
$daterange_season = array('2017-01-20', '2017-02-15'); /* 20 January 2017 - 15 February 2017 : Season */
$daterange_booked = array($book_start_date, $book_end_date);
$range_min = new DateTime(min($daterange_season));
$range_max = new DateTime(max($daterange_season));
$start_book = new DateTime(min($daterange_booked));
$end_book = new DateTime(max($daterange_booked));
if ($start_book >= $range_min && $end_book <= $range_max) {
echo 'Yes. Within season. Charge me!';
} else {
echo 'My booking is not within Peak Season, dont charge me!';
}
?>
20 January 2017to02 February 2017.