I’ve been notified that something I’ve written isn’t working (and potentially hasn’t been for a few months if what I think is the problem is actually the problem…!)
I’m based in the UK, so work with GMT / BST
I’m getting the date and hour and then running a SQL function to perform an update based on the results, so my code is something along the lines of…
$day = date("j M Y", mktime());
$hour = date('H',time());
$hourend = $hour + 1;
$from = $day . " " . $hour . ":00:00";
$to = $day . " " . $hour . ":59:59";
And then a SQL query to get the results for the update:
select username, dms from MISYearToDate('$from', '$to')
So, will I need to change the $hour based on whether or not we are in daylight savings?
e.g.
$isBST = date("I", $day);
IF ($isBST == 1)
{
$hour = $hour + 1;
}
Or will is do this for me automatically?
If both your database server and your web server run in the same timezone, it should work automatically as expected.
Otherwise, I’d strongly suggest you run all your servers in UTC to avoid any timezone issues. You just need to assure you’re converting UTC to the users’ timezone in your View layer.