I have a MySQL database in which one column is of type DATETIME and stores the values in IST (as my server time zone is IST).
I am getting a two string in EST from the user for which I need to match the date part in my database with that column.
I am using this query :
SELECT * FROM my_table where date(convert_tz(`myDate`,'+05:30','-05:00'))
between '2012-12-01' and '2012-12-02';
Note: That in my database mysql.time_zone is empty meaning I cannot use strings likeGMTetc in my query, they instructed me to download a package, but I don't want to download it, its fine for me to use00:05` as I will be framing my query in Java.
This query runs fine as I have hardcoded the the time zone offset (for EST.
But I am worried that this query will give wrong data for the dates that fall in Daylight timings i.e. for EDT.
So how do I get the time zone difference (meaning it should return ‘-05:00’ for EST and ‘-04:00 for EDT ) so that I can directly use them when building my query string in java.
My query string may look like :
SELECT * FROM my_table where date(convert_tz(`myDate`,'+05:30','???'))
between '2012-12-01' and '2012-12-02';
where I want the value at ??? to be dynamically allocated using a prepared statement.
I am using Joda Time API, but don’t have much knowledge of it, whether it has something that can return me the timezone offser for a given timezone string.
I would suggest that:
DateTimeset in the right time zone, and then converting to UTC)If you really, really can’t change the database to use UTC instead, you should convert your “target timezone” values into IST values instead, and pass those to the database. Again, the query doesn’t need to do conversion: convert your inputs beforehand instead.