So I'm making a website for this pizzeria.
In the past I made a simple window that pops up Monday-Friday & Between 11.30am-02:00pm which is simple enough.
But now I've had a request to do the same thing, but instead of having a single "Lunch Buffe Ongoing!" box, the client want's a daily menu (different menu every day, which is also easy enough), but he has 3 different daily menus alternating every week.
So here's an example: Week 1 Menu: Monday: w1m1 Tuesday: w1m2 ..
Week 2 Menu: Monday: w2m1 Tuesday: w2m2
So my question is: Is there a PHP function / equation for calculating "is it the first, second or third" week from a specified starting date
Edit (Not duplicate because): This isn't a duplicate of PHP get number of week for month because I'm not asking for the week number, I'm asking what week this is alternating with 3
Answer:
<?php
function menuNumber($now) {
$then = '26/05/2014';
$first = DateTime::createFromFormat('d/m/Y', $then);
$second = DateTime::createFromFormat('d/m/Y', $now);
$calculated = (floor($first->diff($second)->days/7) % 3) + 1;
return $calculated;
}
echo "Menu Number " . menuNumber(date("d/m/Y")); // Menu Number 1
?>
Help From: php weeks between 2 dates