Help with Silly Bit of Code!
3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 25, 2013 (RSS)
Hello, All -
I'm using a tiny bit of code on my latest CMSB website which is designed to show a different graphic on alternating weeks.
$weekNo = strftime('%U');
if ($weekNo%2)
{
do normal
}
else
{
do alternate
}
It works fine. The only problem is that the code updates on Sunday - whereas I need it to change on Thursday!
Can anyone help?!
:0)
Perchpole
Hi Perchpole,
This is a good brain teaser for a Friday morning! Here is how I would do it:
<?php
if(date('W',strtotime ( '+4 day' )) % 2 == 0){
echo "This week is even";
}else{
echo "This week is odd";
}
?>
So the strtotime function gets the current date plus 4 days, so Thursday plus four days is Monday. Then the date function is converting the time into a string with the week of the year for that date. Then you just need to work out if the week is odd or even using %2 ==0.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com
Greg -
You're a star. It works perfectly. Now everyone will know which colour rubbish bin to put out for collection every week!
:0)
Perch