Help with Silly Bit of Code!

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 25, 2013   (RSS)

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

Greg Thomas







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