Clément Andraud February 2016

Compare BST date with UTC + 1 date

I have a string date like : 2016-02-12 19:30:00

This date is in BST timezone and I need to compare this date with today date. I am french so it's UTC + 1.

What's the solution ? If I add one hour to my BST date, it is correct ? Do I need to convert BST to UTC + 1, or UTC + 1 to BST ?

For now I retrieve today like : $today = date("Y-m-d H:i:s");, and I compare my two dates like :

if(date('Y-m-d H:i:s', strtotime($myBstDate)) >= $today)

For me it is wrong, there is an offset of one hour.

What's the correct way ? Thanks !

Answers


Álvaro González February 2016

Legacy date functions are not particularly suitable for date math with time zone information. It's rather straightforward though if you use objects:

$date = new DateTime('2016-02-12 19:30:00 BST');
if ($date>=new DateTime) {
}

Post Status

Asked in February 2016
Viewed 1,697 times
Voted 10
Answered 1 times

Search




Leave an answer