EST/EDT to GMT conversion and date comparison

I need to convert a given GMT date and time (YYYY-MM-DD HH:MM) into such a string YYYYMMDD representing Eastern coast date. Do you think the code below is OK?

$date='2011-11-07 04:30';
$date.='-4 hours';
$date=strftime('%Y-%m-%d %H:%M',strtotime($date));
$date2=date('Y-m-d 02:00',strtotime($y.'-03-01 second sunday'));
$date3=date('Y-m-d 02:00',strtotime($y.'-11-01 first sunday')); 
if($date<=$date2||$date>=$date3) {      
  $date.='-1 hour';
  $date=strftime('%Y-%m-%d %H:%M',strtotime($date));
$date=date('Ymd', strtotime($date));


I'd advise against trying to do the calculation yourself. There's too many nuances with our wonderful, ever-changing, time standard. Instead, rely on PHP to perform the calculations by using to set your timezone to GMT, then strtotime() (or the DateTime class) to get the unix-timestamp value.

Once you have the unix timestamp, use again to set the timezone to America/New_York and use date()

Need Your Help

Mocha breakpoints using Visual Studio Code

node.js tdd mocha bdd vscode

Is it possible to add breakpoints to ones Mocha tests using Visual Studio Code?

How to use a loop variable outside the loop?

php arrays variables loops while-loop

I am trying to use $description variable outside the loop. Help me do it please.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.