You need to sign in to do that
Don't have an account?

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.
yyyy-mm-ddT00:00:00.000Z
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?
You'll be wanting "system.now()".
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.
Huh, what do you know? According to the docs, they are identical. Both return the current datetime based on GMT.
Hmm... that's pretty interesting.
Thank you for your help.
Valid date format: MM/DD/YYYYThh:mm:ss.mmmTimeZone
(example: 02/20/1987T12:04:12.000GMT+01:00)