+ Start a Discussion
astroastro 

API DateTime field access clarification question

I have a requirement which asks me to retrieve only those records that have been modified after a given day.

 

The problem I have is that I know salesforce stores DateTime fields in UTC format and the Timezone the java code is running from is in PST.

 

how do I form my query?  Should it be in the following way (PST has a -8 difference from UTC time)?

 

select ID from Account where LastModifiedDate > 2009-12-09T00:00:00.000-08:00 

 

This doesn't seem to be retrieving the desired results.  I do understand that the time displayed in sfdc and if I were to query for an accounts LastModifiedDate field would display in the timezone according to my profile.  My profile I am using within Java has a Timezone of PST.  So do I even need to convert the timezone or should the query read as follows instead?

 

select ID from Account where LastModifiedDate > 2009-12-09T00:00:00.000Z

 

Thank you in advance for your responses.  

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
mpiercempierce

It's easier to just always use UTC. That way you don't have to worry about changing offsets when daylight saving time starts, etc.

 

You should figure out what time you want to compare to in your local time zone then convert it to UTC (Zulu time) and use that in your SOQL statement.

All Answers

mpiercempierce

It's easier to just always use UTC. That way you don't have to worry about changing offsets when daylight saving time starts, etc.

 

You should figure out what time you want to compare to in your local time zone then convert it to UTC (Zulu time) and use that in your SOQL statement.

This was selected as the best answer
astroastro

Thank's for responding (again) mpierce :)

 

so if I understand correctly, and if my timezone is pacific time which is 8 hours behind UTC I should format my query accordingly:

 

select ID from Account where LastModifiedDate > 2009-12-09T00:00:00.000+08:00  

 

this should give me all Accounts which have been Modified since Dec. 12 2009 since 12:00:00am. Is that correct?

 

Thank's again for responding. 

mpiercempierce
Well, you'd probably want -08:00 instead of +08:00, but I still recommend just using UTC for everything.
astroastro

Sorry, I understand what you mean now.  I will convert the time to UTC in java and use the UTC time in my sfdc query.

 

 Thank you for clearing this up.