+ Start a Discussion
V AnandV Anand 

How to compare datetime fields in trigger?

 

Field that records the Date/Time of the last received lead. Now  I want to compare  current date  with previous date of same field.

 

Could you please any one write coding for above....... 

Bhup@esplBhup@espl

Campare your dateTime field with "isSameDay".

 

datetime myDate = datetime.now();

datetime previousDate = datetime.newInstance(2008, 1, 30);

boolean dueNow = myDate.isSameDay(dueDate);

Bhup@esplBhup@espl

I missed to change variable name

 

datetime myDate = datetime.now();

datetime previousDate = datetime.newInstance(2008, 1, 30);

boolean dueNow = myDate.isSameDay(previousDate );

_Prasu__Prasu_

In after insert trigger you can get old values and new values array for the records which have fired the trigger. you can compare the old values and new values and do the needful.