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
Milan HrdlickaMilan Hrdlicka 

insert datetime in a custom object

Hello,

I have a datetime field in which I need to insert date and time - 5th December 2016 7:30 AM.
I tried below code but I guess the datetime format is invalid as I get an error: Line: 5, Column: 23
unexpected token: '2016-12-05'
Anyone knows a valid date format, does it depend on my current location? 
Appreciate your help.

Milan

try {

   Opening_Hours__c openHours = [select Name, Day_Of_Week__c from Opening_Hours__c where Name = '1' AND Day_Of_Week__c ='Monday'];

   openHours.Open__c = 2016-12-05 07:30 AM;

   update openHours;

    } 

catch(Exception e) {
    System.debug('An unexpected error has occurred: ' + e.getMessage());
}
Ragava reddyRagava reddy
Hi Milan,

You have to use DateTime.Parse(YourDate__c);

Thanks,
Raghavendra Reddy.D