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

Not getting correct DateTime value in debug log



I have created datetime field in one cutom object. While creating new record, I inserted:


Appointment Date: 2/10/2012 12:45


I have written trigger after insert of above record. In that I have debugged the same field and here I am getting different value.


System Debug
Appointment Date:: 2/10/2012 7:16:00

 Please tell me why dates are coming differently at both places.




The log shows the date/time as UTC.  I'm guessing you're in MST timezone, right?




I am in IST time zone. Can you please tell me why this is happening?




Use valueOfGmt, it Returns a Datetime that contains the value of the specified String. The String should use the standard date format “yyyy-MM-dd HH:mm:ss” in the GMT time zone

system.debug('_____________________________________________'+datetime.valueOfGmt('2012-10-02 12:45:00'));


2012-10-02 12:45:00


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Richa KRicha K

When you specify a date in a SOQL query, it can be a specific date, or a date literal, which is a fixed expression representing a relative range of time such as last month or next year. Remember that dateTime field values are stored as Coordinated Universal Time (UTC). When one of these values is returned in Salesforce, it is automatically adjusted for the time zone specified in your organization preferences. SOQL queries return dateTime field values as UTC values. Your application may need to handle the conversion if you want to process these values in different time zones.


What about the timezone of the user account that you used to insert the record?  Is it MST?


If you login using the same user account (the one you used to create the record), and view the date value in the native SFDC view, you will see that it is displayed as 12:45.  But when you print it in debug logs, it will appear as converted to UTC.