1

Just learning MYSQL sorry and didn't find the answer from searching here as I am confused about timezones etc.

I have a table like the following;

  • time (datetime type with time in my timezone in it - eg "2014-11-21 14:23:45")
  • temp_c (double with temperature at that time)

The server is in a different timezone so I am getting mixed up in how to limit the rows to be sometime today.

So basically I want to find the maximum temperature so far today in my timezone and when it occured, as well as the minimum temperature and when that occured.

Vikdor
  • 23,934
  • 10
  • 61
  • 84

1 Answers1

1
SET time_zone = 'your time zone';
SELECT MAX(temp_c) 
FROM YourTable
WHERE DATE(time) = DATE(NOW());

Replace your time zone with your actual time zone. This can either be an offset from GMT like -05:00 for 5 hours west of GMT, or a zone name like US/Eastern.

SET time_zone = 'US/Eastern';

For more information on time zones in MySQL see

How do I set the time zone of MySQL?

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612