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
Ravi Dutt SharmaRavi Dutt Sharma 

How to save lightning:input type="datetime-local" to database?

It seems that there is a bug with lightning:input type="datetime-local" tag. When I add this tag in my component, thenchoose a date and time using the date time selector and try to save the record to database, apex is not able to take the value? Any pointers on how to save this value to a date time field present on an object. Below is the sample code I am trying to implement:

dateTimeLocal.cmp
 
<aura:component controller="DateTimeLocalCtrl">
    <aura:attribute name="lead" type="Lead" default="{'sobjectType':'Lead','id':'00Q9000001BtwNE'}"/>
	<lightning:input type="datetime-local" label="Start" name="Start" value="{!v.lead.Start__c}"/>
    <lightning:button label="Save" iconName="utility:save" onclick="{!c.doSave}"/>
</aura:component>
dateTimeLocalController.js
({
	doSave : function(component, event, helper) {
		
       var action = component.get("c.upsertLead");
        var lead = component.get("v.lead");
        console.log("*****Date: "+component.get("v.lead.Start__c"));
        // set param to method  
        action.setParams({
            'ld': lead
        });
        // set a callBack    
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log("*****Success");
            }else{
                console.log("*****Failure");
            }
        });
        // enqueue the Action  
        $A.enqueueAction(action);
	}
})

DateTimeLocalCtrl.apxc
public class DateTimeLocalCtrl {

    @AuraEnabled
    public static Lead upsertLead(Lead ld){
        upsert ld;
        return ld;
    }

}


 
sfdcMonkey.comsfdcMonkey.com
hi ravi, yes this is a issue with date time local lightning:input component type :
sara morgan provied a workaround for it please check below link :
https://saramorgan.net/2017/10/01/workaround-for-problem-with-lightninginput-and-datetime-local/
i hope it helps you.
   Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks

 
Ravi Dutt SharmaRavi Dutt Sharma
Thanks, I already had a look at this link. Using the workaround mentioned in the link, it disturbs the time zone, so that workaround won't work. Regards, Ravi Dutt Sharma
sfdcMonkey.comsfdcMonkey.com
opss then let me validate it in my dev org, and can you tell what value you enter in this field ?
 
Ravi Dutt SharmaRavi Dutt Sharma
Select any value in through the date time picker, it will give you an error when you hit the Save button