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
crusader2016crusader2016 

Format to Insert a value to a Date/Time Field

Hi All,

 

I was having a hard time figuring out what is the format that the Date/Time field should acccept. The format I am generating to another source code is 5/17/2011 11:00 or dd/mm/yyyy hh:mm. and Salesforce does not accept when I tried to insert. I also tried using the datetime.valueOf but it still does not work, it says invalid date.

 

Please advise.

David81David81

yyyy-mm-ddT00:00:00.000Z

salesforce_deversalesforce_dever

This may be a silly question but how should we properly format a datetime value for a datetime field for the current date and time?

 

Would:

 

customObject.Date_Time_Field__c = datetime.now();

 

Work?

 

Is that formatted correctly?

David81David81

You'll be wanting "system.now()".

salesforce_deversalesforce_dever

Thank you for the quick response. I have a quick question...

 

If I execute anonymous:

 

system.debug('System Time: ' + system.now());

system.debug('Datetime Time: ' + datetime.now());

 

I get:

 

09:43:06.048 (48402000)|USER_DEBUG|[1]|DEBUG|System Time: 2012-10-03 13:43:06

09:43:06.048 (48458000)|USER_DEBUG|[2]|DEBUG|Datetime Time: 2012-10-03 13:43:06

 

What is the difference between system.now() and datetime.now()?

 

I'm just wondering. The issue I have is some of my dates are being set in the future for some reason.. like 2016-11-02 11:32:05. Not consistenly but enough to make me wonder what is going on.

David81David81

Huh, what do you know? According to the docs, they are identical. Both return the current datetime based on GMT.

 

 

salesforce_deversalesforce_dever

Hmm... that's pretty interesting.

 

Thank you for your help.

Jason Fry 5Jason Fry 5
This is from a DataLoader error message:
Valid date format: MM/DD/YYYYThh:mm:ss.mmmTimeZone
(example: 02/20/1987T12:04:12.000GMT+01:00)