SOQL Date functions CALENDAR_YEAR and CALENDAR_MONTH return values as UTC Timezone values. How to convert those values to specific Timezone, like Europe/Berlin ?

Example time: 2014.07.01 00:00 , Europe/Berlin Timezone. CALENDAR_MONTH() will return 6 (June, UTC Timezone) but I need to get 7.


I think that you can't specify the TimeZone, but you could have the result to the user's timeZone.

You must use convertTimezone

This is un example.

SELECT CALENDAR_YEAR(convertTimezone(CreatedDate)), SUM(Amount)
FROM Opportunity
GROUP BY CALENDAR_YEAR(convertTimezone(CreatedDate))

This is the official doc for convertTimezone

| improve this answer | |
  • Thanks for the answer, Martin. In my case, using convertTimezone would not help because I'm working on global Org and relying on user's timezone would lead to serious issues. What I need to do is to use a specific timezone, which is Europe/Berlin – justasd Feb 28 '14 at 11:20
  • As I told you, I think that is not possible by SOQL. I least I don't know any documented function to do that. You probably must try to get that number by APEX using Date.format – Martin Borthiry Feb 28 '14 at 11:35
  • Strange, but CALENDAR_YEAR(convertTimezone(CreatedDate)) returns UTC timezone, not user's timezone – justasd Feb 28 '14 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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