Jump to content

change information based on date


kirk112

Recommended Posts

Hi

 

Can't seem to get my head around how to achieve this

 

I need to be able to switch between a restaurant menu based on the date.  Currently they are on menu one which is active from the 3rd Feb to 16th Feb and then changes to menu two on the 16th Feb to 2nd March and back to menu one on the 3rd and so on.

 

 

Is they any way I can achieve this with out hard coding all possible dates for the next 3 years?

 

Hope the above makes sense

 

Thanks for your help!

Link to comment
Share on other sites

Hi aschk

 

Thanks for your reply, was hoping that there might be a logical way of performing the calculation

 

i.e. 64 days has past from point A so that means display menu 1 (know that this is way off <--)

 

Not looking for someone to provide the full script just a bit of logic of how this can be done

 

Thanks agains!!

Link to comment
Share on other sites

A bit of a random way for it to work...

 

I'll try and explain it, and if you don't udnerstnad I'll give you some code as I don't have it fully working in my head yet.

  • get the integer value for the start month (so for feburary - 2)
  • check todays month and day, it its not past the third take 1 away from the month so (april 2nd: month int - 3 (march))
  • if the current month subtract the start month is an odd number display menu 2, if its an even number display menu 1
  • if the year has change you'll have to add 12 to the month int

Hope some of that makes sense, I may have amde it sound more complicated tahn it actually is...

Link to comment
Share on other sites

??? ??? ??? ???

 

Kind of understand could be useful if you could supply some code  ;D

 

Just a bit more information not sure if you think it always changes on the 3rd (or if I have misunderstood what you have put)

 

3rd - 16th Feb  Menu 1

17th - 2nd March  Menu 2

3rd March - 16th March Menu 1

17th March -30th March Menu 2

31st March - 13th March Menu 1

 

 

Thanks for your help - the more I try to work this out the more confused I get!

Link to comment
Share on other sites

I think I've got something..... Don't know if it's the best solution, but it's a solution

 

<?php
function menu() {
$start_stamp = strtotime('2009-02-03');//Start date YYYY-MM-DD
$two_weeks = (60*60*24*14);//timestamp equivalent of two weeks
$diff = time()-$start_stamp;//difference between today and start date
$weeks = floor($diff/$two_weeks);//number of weeks since start date (rounded down)
if($weeks%2) {//if odd
	return "menu two";
} else {//if even
	return "menu one";
}
}
echo menu();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.