When getting the selected date from the calendar I alway get something like “Thu Feb 21 2008 00:00:00 GMT-0600 (CDT)”. I need ‘2008-02-21’ and have set the format as below. How can I get the format I want?
…
var mCal = new dhtmlxDblCalendarObject(‘cal_’,false);
mCal.leftCalendar.setOnClickHandler(function(this){setRangeDate(this,‘fromDate’)});
mCal.rightCalendar.setOnClickHandler(function(this){setRangeDate(this,‘toDate’)});
var fromDate = document.getElementById(‘fromDate’).value;
var toDate = document.getElementById(‘toDate’).value;
mCal.leftCalendar.setFormatedDate(’%Y-%m-%d’,fromDate);
mCal.rightCalendar.setFormatedDate(’%Y-%m-%d’,toDate);
mCal.leftCalendar.setDateFormat(’%Y-%m-%d’);
mCal.rightCalendar.setDateFormat(’%Y-%m-%d’);
mCal.draw();
…
setRangeDate = function(calObj,elem){
var d = calObj.getDate();
document.getElementById(elem).value=d;
…
}
Grid supports two different command
calObj.getDate();
- returns javascript date object
calObj.getFormatedDate(); - returns date as string in specified format
Thanks for the prompt reply. Is the getFormatedDate function documented anywhere? I did not see in the cal API docs.
Please, see calendar’s documentation. Try to find the “Formating date” article in the dhtmlx.com/docs/products/dht … guide.html