function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andy CorbettAndy Corbett 

Apex DateTime Discrepancy

Hi all - sorry, I'm not a Developer but have been asked to try and fix this issue!

We have some Apex code which is supposed to take a custom field Completion_Date__c which is on a custom object and generate something called applicationCreateDateTime to put into a JSON file.

The relvant line of code is:

this.applicationCreatedDateTime = String.valueOf((DateTime.newInstance(application.Completion_Date__c, Time.newInstance(0, 0, 0, 0))).formatGmt('yyyy-MM-dd\'T\'HH:mm:ss\'Z\''));

What appears to be happening is instead of it producing the correct value it is creating a date which is the day before and 23:00:00 hours.

E.g the record contains Completion_Date__c = 09/04/2019 11:18

But the resultant field applicationCreatedDateTime contains 08/04/2019T23:00:00Z

I would expect it to show 09/04/2019T00:00:00Z based on that line of code?

Is there anything obvious you can see?