I am building a booking system in php that offers session times for people to book outdoor activities.
In the summer months, there is an extra session available at the end of the day, because of Daylight Savings, there is an extra hour in the evenings.
Year Clocks go forward Clocks go back 2014 30 March 26 October 2015 29 March 25 October 2016 27 March 30 October 2017 27 March 30 October 2018 25 March 28 October
I am using this…
$todaysDate = strtotime(date("Y-m-d")); $bstBegin = strtotime("2015-03-29"); $bstEnd = strtotime("2015-10-25"); if($todaysDate > $bstBegin && $todaysDate > $bstEnd) { echo "<option value="evening">Evening Session</option>"; }
I only need to show this extra option in the select list between these dates. Is this something I will need to set manually from year to year, or is there a PHP date variable that knows the days the clocks change?
Advertisement
Answer
$today = strtotime(date("Y-m-d")); if (date('I', $today)) { echo "We're in BST!"; } else { echo "We're not in BST!"; }
or use the DateTime object equivalent, which maintains details of all the transition dates globally