Ej Calendar DatePicker getting wrong value.

Hi I have a datepicker which i formatted to 'dd/MM/yyyy' but when i get its value it is giving me 'MM/dd/yyyy' format value.

Here's my code:

var decisionDate = new ej.calendars.DatePicker({
   format: 'dd/MM/yyyy'
},'#decision_date')); decisionDate.value = "03/01/2008"; // This is supposedly to be January 3, 2018
console.log(decisionDate.value); // But when i get its value. It gives me March 1, 2018 (Sat Mar 01 2008 00:00:00 GMT+0800 (Philippine Standard Time)

Can you please help me about this issue? Thanks.
Regards,
Robin

3 Replies

DL Deepa Loganathan Syncfusion Team October 25, 2018 12:38 PM UTC

Hi Robin,  
 
Thanks for contacting Syncfusion support.  
 
We understood your requirement to accept the date format of “dd/MM/yyyy” in the Philippines culture.  
 
The format API of Datepicker refers to the display format of the Datepicker that means the Datepicker would accept string and Dateobject supported by the Javascript’s Date constructor and display Date in the Datepicker’s format API.  
 
Since Datepicker constructor accepts the Date string in the format of “MM/dd/yyyy” for Philippines culture, you would need to pass the date value as explained in the below stackoverflow thread.  
  
 
For your reference, we have prepared a sample based on your requirement and is available for download under the following link. 
 
 
Here, we have converted the Date string of format “dd/MM/yyyy” to a Date object before passing it to the Datepicker component as given in the below code.  
 
    
 function getDate(e: string):Date{ 
         
        var dateParts = e.split("/"); 
 
        var dateObject = new Date(Number(dateParts[2]), Number(dateParts[1]) - 1 , Number(dateParts[0]) ); // month is 0-based 
 
        return dateObject; 
 
    } 
 
 
Also, we would like to let you know that passing Date value as an object instead of String is the most preferred way. 
 
Please let us know if you have any further queries.  
 
Regards,  
Deepa L. 



RL Robin Leo Zapata Lamatao October 26, 2018 01:44 AM UTC

Hi Deepa,

This solution solves it. Thank you very much! 

Regards,
Robin


DL Deepa Loganathan Syncfusion Team October 26, 2018 09:29 AM UTC

Hi Robin,   
 
You are most welcome. Please let us know if you have any further queries. 

Regards,  
Deepa L. 


Loader.
Up arrow icon