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
dnvansantdnvansant 

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()))

 

dnvansantdnvansant

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.

vriavmvriavm

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

Can you check this?

L0bster1L0bster1

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.

vriavmvriavm

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.