0

I have two Date/Time fields : StartTime and EndTime When queried, it result is not correct. It is showing 1hr less than actual.

Example: Actual Data
Start Time - 18/05/2017 08:30
End Time - 18/05/2017 18:00

Result after queried:
Start_Time__c: 2017-05-18 07:30:00
End_Time__c: 2017-05-18 17:00:00

It shifting 1hrs back.

Please share your thoughts if you have any Idea.

1
  • If this question is resolved, could you please accept one of the answers below?
    – Adrian Larson
    Sep 18, 2017 at 13:30

2 Answers 2

0

From documentation

dateTime field values are stored as Coordinated Universal Time (UTC). When a dateTime value is returned in Salesforce, it’s adjusted for the time zone specified in your org preferences. SOQL queries, however, return dateTime field values as UTC values. If you want to process these values in different time zones, your application might need to handle the conversion.

So it is possible that when you're storing date in Salesforce it's getting converted into UTC format and that's why it is returning in that format only. You can convert that dateTime into different time zones as per your need.

0
0

I found solution of this issue.

public Double offset{get{
TimeZone tzone = UserInfo.getTimeZone();
//Milliseconds to Day
return tzone.getOffset(DateTime.now()) / (1000 * 3600 * 24.0);}}

And then we need to add offset to the retrieved values.

You must log in to answer this question.

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