0

I am looking for a way to do something, I have never done before.

I have the Query as

SELECT DATE_FORMAT(CONVERT_TZ(pi.start,'+00:00','+10:00'), '%Y-%m-%d %h:%m:%s') as start,
ifnull(dc.name,'Unknown') as source,
format(sum(ifnull(pi.rev,0)),2) as revenue
from trk.provider_imp pi
left outer join trk.dsp_client dc
on pi.clientid = dc.id
and type = 'client'
where pi.start between DATE_SUB(DATE_FORMAT(NOW() ,'%Y-%m-01'), INTERVAL 5  MONTH) AND DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH),'%Y-%m-%d')
and pi.status = 1
group by start,pi.clientid
order by pi.start, pi.clientid;

The above query works and I get the results that I desire, however, for the Time Zone Conversion, I am an hour behind, for Nov, Dec and Jan.

Is there a way where I could add a if statement, and that would do something like, if 'start' is in ('Nov 2014','Dec 2014', 'Jan 2015', than 'start' plus one hour)?

1 Answer 1

0

To do what you need, the simplest and most effective way I have found was to use your actual location as a parameter, and not the GMT offset.

For instance, if you are in Melbourne, instead of using '+10:00' in Winter and '+11:00' in Summer, you would simply mention 'Australia/Melbourne' in the timezone parameter. Doing this will take care of the daylight savings time offset.

Your example mentioned +10, I'm assuming Melbourne; these 2 statements will return different times as the DST offset is different:

SELECT CONVERT_TZ('2015-01-01 02:00:00','UTC','Australia/Melbourne');
SELECT CONVERT_TZ('2015-10-01 02:00:00','UTC','Australia/Melbourne');

The caveat is that standard MySQL installations do not come with the timezone names built-in. Follow these instructions to get those in your MySQL server: http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.