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
O2O SimonO2O Simon 

Problem with date

Dear all,

When i insert an event by the below code :

Contact c = [select id from Contact where Email = 'peterchan@hotmail.com'];
Event event1 = new event(subject='call', whoid=c.id, DurationInMinutes=60, ActivityDateTime=2008-12-01T12:00:00Z);   
insert event1;

I got this error :
Error: Compile Error: unexpected token: 2008-12-01T12:00:00Z at line 14 column 137

Could anyone tell me what's wrong with the date?

Thank you very much
Ron HessRon Hess
here is an example, note i had to take out the "T" and remove the Z, to match what valueof expects


Code:
   Contact c = [select id from Contact where Email = 'peterchan@hotmail.com'];
Event event1 = new event(subject='call', whoid=c.id, DurationInMinutes=60 );
event1.ActivityDateTime= Datetime.valueof('2008-12-01 12:00:00');   
insert event1;

   

 

/*
Datetime valueOf String s Datetime


datetime.valueof( string )

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 local time zone
*/