5

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.

1 Answer 1

3

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

3
  • 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
    Commented Feb 28, 2014 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 Commented Feb 28, 2014 at 11:35
  • Strange, but CALENDAR_YEAR(convertTimezone(CreatedDate)) returns UTC timezone, not user's timezone
    – justasd
    Commented Feb 28, 2014 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .