I have a lightning component which has a datetime field, the value of which is auto-initialized with the component's helper.js. The default initialized value is supposed to be today's date and the next full hour(e.g If local time is 10:23, the default value should be today's date and 11:00 time).

Component code :

<aura:attribute name="defaultdateTime" type="datetime"  default=""/>
<lightning:input type="datetime" name="myDate__c" timezone = "GMT" aura:id="inField" value="{!v.defaultdateTime}" dateStyle="Medium" min="2017-08-03 07:00:00Z" max="3000-09-25 17:00:00Z" label="{!v.objDesc.myObject__C.myDate__c.label}" />

Helper.js code :

(I am using the new Date() to get current Date and formatting it further by seperating in JS)

var formattedDefaultdateTime = defaultdate.getFullYear() + "-" + defaultMonth + "-" + defaultDay +"T"+fullhour+":00:00Z";

Now, for some reason this code is working absolutely perfect after 9am in local time. Before 9am local time, the field does not autopopulate. I tried debugging and the code is working correctly on Helper.js side. The ORG default timezone is set to CEST (GMT + 02:00) and the Business hours are set to default Pacific Daylight time (GMT - 07:00), although I am not able to factor them in as for all country timezones, it is 9:00am local time specifically.

Issue : What is this 9am parameter before which salesforce field isn't initializing?

Any help or direction towards a probable cause would be appreciated. Thank you.


1 Answer 1


The HTML code will work fine, You will have to make changes in your JS code

    var defaultdate = new Date();
//getUTCMonth does not return preceding zero. This line will add the zero and it is mandatory
    var month = ("0" + defaultdate.getUTCMonth()).slice(-2); 
    var formattedDefaultdateTime = defaultdate.getUTCFullYear() + "-" + month + "-" + defaultdate.getUTCDate() +"T09:00:00Z";
    component.set('v.defaultdateTime', formattedDefaultdateTime);

make sure to keep the timezone = "GMT" unchanged in your HTML lightning:input tag. This will preserve your date's UTC formatting.

  • So, I have a console.log(formattedDefaultdateTime) setup before the component.set() method and I can see that the date is being formatted correctly at all times. But, just before 9am local time, it doesn't get populate in the field, while after 9am, it populates correctly.
    – D.Kat
    May 16, 2022 at 10:44
  • it actually does, make sure timezone = "GMT is added to your input tag May 16, 2022 at 14:05
  • timezone is set to GMT for my lightning input at all time. But, even if i change the timezone, this issue still persists at 9am local time.
    – D.Kat
    May 17, 2022 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .