+ Start a Discussion

Date.Today() Returning Wrong Date???

Can any one tell me why the code below would return the value


8/1/2012 8:00 PM
when the code was executed at


8/2/2012 3:38 PM EDT


The code was executed in the sandbox by a user in the EDT timezone.


LeadsToUpdate.add(new Lead(Id=l.id, Date_Demo__c = Date.today()))



The code updates date fields with the correct date, but provides the wrong date when populating a date/time field. Does that make sense to anyone? It seems odd.


It depends on the user timezone/Organizantim Time Zone settings....

Can you check this?


I looked at that and it's not a timezone thing. When I populated the date/time field with system.now everything worked fine. However, date.today produced the screwy results described above.


I've fixed the issue by using system.now instead of date.today when populating date/time fields. I have no idea, though, why the two methods produced different days.


One thing to note is system.today() will return Date and system.now() will return DateTime. This is why you are seeing different results for the two methods.