I’m trying to get the last Sunday between two week numbers – in order to avoid DST.
IN ORDER WORDS: Start a range of time – from the last Sunday in March to the last Sunday in October.
This is my code:
$heloo = gmdate('U');
if ( (date("W", $heloo) >= 12)
&& (date("W", $heloo) <= 43)
&& (date("N", $heloo) == 7) ) {
echo "YES Day is: ".date("N", $heloo). "<br />
Week is: ". date("W", $heloo);
} else {
echo "NO Day is: ".date("N", $heloo). "<br />Week is: ". date("W", $heloo);
}
The weeks seems to work fine but the days doesn’t work at all. Could you please point me to the right direction or advice where to get some help?
🙂
Try this easy piece of code:
So, use it this way
Output
Also, if default time zone is not set in your php config (php.ini) add something like this at start of your script to avoid throwing warnings in PHP.
To print this result out to screen use
If you want to do it without using function
Output
Note: DST doesn’t affect dates in this case.
Your code looks like unnecessary complication 🙂