0

From lightning component, when I select the startdate and end date, I should able to select in MM-DD-YYY. But from backend Apex, it is coming as YYY-MM-DD 00:00:00. I want to convert this into that format. How can I do it?

Below is my code markup:

<ui:inputDate aura:id="startDate" required="true"   class="field"  displayDatePicker="true"   value="{!v.StartDate}" format="MM-DD-YYYY" blur="{!c.changeDateFormat}"/>

<ui:inputDate aura:id="endDate" required="true"   class="field"  displayDatePicker="true"   value="{!v.EndDate}" format="MM-DD-YYYY" blur="{!c.changeDateFormat}"/>
0

Please check the link below and compare the 2 input-types: Date (entering a date) and Datetime-local (entering a date and time). https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_input.htm

-1

The controller (js) is receiving the value correctly, right? (MM-DD-YYYY)

That's a string, so your apex code needs to receive a String too, for exemple :

Component:

<ui:inputDate aura:id="date-id" value="{!date}" displayDatePicker="true" blur="{!c.fldChanged}"/>

Controller :

fldChanged : function(component, event, helper) {
        var dateComponent = event.getSource();
        var newDateJs = dateComponent.get("v.value");
        var action = component.get("c.updateVisitDate");
            action.setParams({newDate: newDateJs });
            action.setCallback(this, function(response) {
                var state = response.getState();
            if (state === 'SUCCESS'){                  
                $A.get('e.force:refreshView').fire();
            }
        });
        $A.enqueueAction(action);

Apex:

@AuraEnabled
public static void updateVisitDate(String newDate){
     // do your stuff   
}  
1
  • 1
    Date type will work here, no need to pass as String and then convert to Date. Apr 22 '18 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.