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
bryanobryano 

Date bug in AJAX Beta2 Toolkit?

I think there might be a bug in the AJAX beta 2 toolkit.  I'm on Eastern Standard Time and I'm trying to set a GMT time into a date/time field in salesforce.  The date being saved in salesforce always seems to be 1 day off when I enter any time between 7:00 PM EST - 11:00 PM EST/

I have a s-control with a text field that has the following value: 3/15/2006 7:00 PM
Here's my code: (logMessage() is a function that displays debugging message on my screen)

var date = new Date(form.textField.value);
logMessages("date is " + date); displays Wed Mar 15 2006 19:00:00 GMT-0500 (Eastern Standard Time)

logMessages("setting UTCYear to " + date.getUTCFullYear()); displays 2006
logMessages("setting UTCMonth to " + date.getUTCMonth()); displays 2
logMessages("setting UTCDate to " + date.getUTCDate()); displays 16
logMessages("setting UTCHours to " + date.getUTCHours()); displays 0
logMessages("setting UTCMinutes to " + date.getUTCMinutes); displays 0
logMessages("setting UTCSeconds to " + date.getUTCSeconds()); displays 0

date.setUTCFullYear(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
date.setUTCHours(date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());

Then I set the field with something like: field.set("myCustomField__c", date);

When I pull the date back in to the scontrol, I get 3/14/2006 7:00 PM

Now when I extract the value being saved with the data loader this is what I get:
2006-03-15T00:00:00.000Z (notice it's setting gmt date to the 15th and not the 16th).

This happens with any time between 7 pm - 11 pm EST.  If I enter 12:00 AM, I get the correct date and time.

Is there a fix for this?




   
luisdluisd
  1. Try using DateTime instead of a Date. From the API documentation: Unlike dateTime fields, date fields contain no time value-the time portion of a date field is not relevant and is always set to midnight in the GMT/UTC time zone.
  2. Months are 0-indexed. 0 is January, 2 is March.
  3. Issues managing dates in form fields were reported in this post. Check them out.

Hope this helps.

Luisd