change the output of datepicker to normal YYYY/MM/DD format

hello 

I want to change the output of the datepicker form Tue Oct 13 2020, 00:00:00 GMT-400 (Eastern Daylight Time) format to just regular YYYY/MM/DDD format so that I can submit the selected value into my database. Is this possible if so how do I do it  

please advise 

3 Replies 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team October 15, 2020 03:39 PM UTC

Hi David, 



Greetings from Syncfusion support. 


We checked the reported requirement. You can format the date object to given format using the globalize method which can be accessed through ref of the component.  Refer to the below code and sample, 



  onclick: function (e) { 
    var instance = this.$refs.date.ej2Instances; 
    var formattedValue = instance.globalize.formatDate(instance.value, { 
      format: "yyyy/MM/ddd", 
    }); 
 
    alert("Selected value is: " + formattedValue); 
  }, 




Please find the sample below, 




Kindly check the above sample and get back to us if you need further assistance. 


Regards, 
Sevvandhi N 



DW David Wisenbaugh November 4, 2020 03:38 AM UTC

How can I add this format to the datepicker control so that I can submit it to my database 
please advise


SN Sevvandhi Nagulan Syncfusion Team November 4, 2020 10:17 AM UTC

Hi David, 


Thanks for the update. 


We checked the reported requirement. If you want to convert the date object in the submit event to a specified format(yyyy/MM/ddd), we recommend that you use the previously given solution. Otherwise, if you want to show the selected date in the specified format as well, then we recommend that you set the format to DatePicker control. Refer to the following code, 

export default Vue.extend({ 
  data: function () { 
    return { 
      waterMarkText: "Choose a date", 
      dateValue: new Date(), 
      format: "yyyy/MM/ddd", 
    }; 
  }, 
  methods: { 
    onclick: function (e) { 
      var instance = this.$refs.date.ej2Instances; 
      var formattedValue = instance.globalize.formatDate(instance.value, { 
        format: "yyyy/MM/ddd", 
      }); 
 
      alert("Selected value is: " + formattedValue); 
    }, 
  }, 
}); 



Please find the sample below, 




Please check the above suggestion and get back to us if you need further assistance. 


Regards, 
Sevvandhi N 


Marked as answer
Loader.
Up arrow icon