I want to edit the date format inside the label from YYYY-MM-DD to MM/DD/YYYY

<ui:inputSelectOption text="{!event.Id}" label="{!event.Name + ' - ' + event.Event_Start_Date__c}" class="eventList" />

Is there any way to do this while still keeping it inline with the event name?

EDIT: Added my controller

public static List<Event__c> getEvents() {
return [Select Id, Name, Event_Start_Date__c From Event__c order by Id desc LIMIT 5];
  • can you modify the Event_Start_Date__c value in the apex class(assuming you are passing it from the Apex controller")
    – Rao
    Jul 24, 2017 at 19:27
  • I am passing it from the apex controller, what do you mean modify it? Jul 24, 2017 at 19:59
  • I tried modifying the date in the apex controller, the format(string) method is deprecated so instead of wasting time there , I took the easy route by altering the response from the server in the JS controller.
    – Rao
    Jul 24, 2017 at 21:38

1 Answer 1


Assuming you are getting Event_Start_Date__c from Apex controller using enqueaction and you are open to modify the Event_Start_Date__c in your js controller, you can try the following code:

I looked at some examples on how to transform the date to mm/dd/yyyy format using JS and applied the same idea here (I have used createddate, you can change the code to accommodate Event_Start_Date__c) :


 if (state === "SUCCESS") {
                var tempholder= [];
                var Items = response.getReturnValue();
                for(var i=0;i< Items.length;i++){
                    var dateval = Items[i].CreatedDate.slice(0, 10).split('-');
                    Items[i].CreatedDate =  dateval[1] +'/'+ dateval[2] +'/' + dateval[0];
                component.set("v.contacts", tempholder); 


enter image description here

  • That worked great actually, never thought of doing it in the js controller. Smart man, thanks!! Jul 25, 2017 at 16:47
  • Honored :). Happy that I was able to help
    – Rao
    Jul 25, 2017 at 16:48

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.