Note that there are some explanatory texts on larger screens.

plurals
  1. POphp determine if a range of dates fall on a weekend
    primarykey
    data
    text
    <p>I am building a a script to detect whether or not certain dates fall on a weekend every year. </p> <p>The 25th and 26th are bank holidays, and if they fall on a weekend the next weekday is a substitute for that bank holiday and the remaining weekdays are working days.</p> <p>Example: if the 25th is a saturday and 26th is a sunday, 27th and 28th will be bank holidays and then 29th, 30th, 31st are working days</p> <p>if the 25th is a sunday, 26th and 27th, will then be bank holidays and 28th, 29th, 30th will be working days and the 31sy will be a saturday.</p> <p>Here are my dates:</p> <pre><code>date('25-12-Y'); date('26-12-Y'); date('27-12-Y'); date('28-12-Y'); date('29-12-Y'); date('30-12-Y'); date('31-12-Y'); </code></pre> <p>The code i have created is this: (please note the $getyear var is to test different years)</p> <pre><code>function isWeekend($date) { return (date('N', strtotime($date)) &gt;= 6); } $getyear = 2013; echo '25 '; if (isWeekend(date('25-12-'.$getyear))){ echo 'weekend'; } else { echo 'bh'; }; echo '&lt;br&gt;'; echo '26 '; if (isWeekend(date('26-12-'.$getyear ))){ echo 'weekend'; } else { echo 'bh'; }; echo '&lt;br&gt;'; echo '27 '; if (isWeekend(date('27-12-'.$getyear ))){ echo 'weekend'; } else { echo 'leave'; }; echo '&lt;br&gt;'; echo '28 '; if (isWeekend(date('28-12-'.$getyear ))){ echo 'weekend'; } else { echo 'leave'; }; echo '&lt;br&gt;'; echo '29 '; if (isWeekend(date('29-12-'.$getyear ))){ echo 'weekend'; } else { echo 'leave'; }; echo '&lt;br&gt;'; echo '30 '; if (isWeekend(date('30-12-'.$getyear ))){ echo 'weekend'; } else { echo 'leave'; }; echo '&lt;br&gt;'; echo '31 '; if (isWeekend(date('31-12-'.$getyear ))){ echo 'weekend'; } else { echo 'leave'; }; echo '&lt;br&gt;'; </code></pre> <p>I know this is probably not best practice, so i am looking for an alternative way to approach this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload