0

I currently have a movie theater website I'm working on in which we display showtimes in a tabbed panel that automatically updates at midnight each night. Each tab has a code similar to:

$sql = SELECT * FROM showtimes WHERE DATE(`date`) = DATE(NOW())";

for today, then tomorrow would be the same but DATE(NOW())+1";, and so on. After that line I echo out the relevant elements into the panel. I understand my code is probably not the best as I'm a beginner but it does work the way it should.

The issue I'm having is that the server is on the west coast and I'm in the Central time zone. Due to this, the tab panels don't update until 2:00 AM my time. I tried adjusting the timezone in the php.ini file but that didn't help. Is there a way I could adjust my code so that it compensates for the 2 hour difference in my time vs server time?

Thank you.

Matt
  • 2,851
  • 1
  • 13
  • 27
Mike T
  • 1

1 Answers1

0

Your query uses MySQL built-in date and time, which will never be affected by the php.ini or any PHP date_time functions, your solution would be to add +2 hours to your query and then try to test the code again, so your script would be:DATE_ADD(NOW(), INTERVAL 2 HOUR)

$sql = SELECT * FROM showtimes WHERE DATE(`date`) = DATE_ADD(NOW(), INTERVAL 2 HOUR)";
zachu
  • 671
  • 2
  • 7
  • 19
Ray A
  • 1,283
  • 2
  • 10
  • 22
  • Ok, I tried changing the code to that but now the text that is supposed to echo isn't appearing. – Mike T Mar 11 '16 at 08:41
  • Sorry for the mistake, the query should be the following: $sql = SELECT * FROM showtimes WHERE DATE(`date`) = DATE_SUB(NOW(), INTERVAL 2 HOUR)"; – Ray A Mar 11 '16 at 10:02
  • because it runs on +2 hours of the current time, we have to subtract it. – Ray A Mar 11 '16 at 10:03