+ Start a Discussion
zachzach 

Quick SOQL Date question...

Hey, just wondering how the time zone offset works with SOQL.

If I specify a query as follows:

Select Id from Case where (CreatedDate >= 2006-07-13T00:00:00-07:00 and CreatedDate <= 2006-07-17T23:59:59-07:00 and RecordTypeId = '[some record type id]'

Will the first date constraint automatically get records from the previous day or not?

In this case, it should return records created after 5:00PM on 7/12/2006, right?
SuperfellSuperfell
All dates are normalized to GMT, then the comparision is done, so if the TZ offset takes you over a date boundary, its correctly applied. It is however important to note that a tz offset of -07:00 means you are 7 hours behind GMT, so 2006-07-13T00:00:00-07:00 is actually 7am July 13 2006 in GMT.
zachzach
Cool on the date thing, but the time zone offset seems a little backwards.

When I look at my time zone settings in Windows, my time zone is Mountain Time & it says GMT-07:00, or 7 hours behind GMT.  When it's 12:01AM on the 23rd in Grenwich, it's 5:01PM on the 22nd in Denver, right?
SuperfellSuperfell
Correct, 2006-07-17T00:01:00Z and 2006-07-16T17:01:00-07:00 are equivilent.
SuperfellSuperfell
You're original example though is reversed of that one. 2006-07-17T17:00:00-07:00 means its 5pm on July 17 2006 and 7 hours behind GMT or midnight on July 18 2006 GMT.
zachzach
Woah, thanks for clearing that up & making me realize all my code is a little hosed up.