SOQL: converting Date functions return values to specific timezone

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.

Answer

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

Attribution
Source : Link , Question Author : justasd , Answer Author : Martin Borthiry

Leave a Comment