Reputation: 6184
I am using jquery datepicker, I want to set min date and max date to show dates. I need to allow user to select date Within min and max range. And dateformat also I need to set based on the user locale.
And I have 2 date field Start date and End date.
$(function(){
var d = new Date();
var minD = new Date("12/02/2012"); //DD/MM/YYYY
var maxD = new Date("12/04/2012");//DD/MM/YYYY
$('#startDate').datepicker({
changeMonth: true,
changeYear:true,
dateFormat: "DD/MM/YY",
monthNamesShort:getTitleMonths(),
dayNamesMin:getTitleDays(),
constrainInput: true,
minDate: new Date(minD.getFullYear(), minD.getMonth(), minD.getDate()),
maxDate: new Date(maxD.getFullYear(), maxD.getMonth(), maxD.getDate()),
changeFirstDay: false});
$('#endDate').datepicker({
changeMonth: true,
changeYear:true,
dateFormat:getDatePattern(),
monthNamesShort: getTitleMonths(),
dayNamesMin: getTitleDays(),
constrainInput: true,
minDate: new Date(minD.getFullYear(), minD.getMonth(), minD.getDate()),
maxDate: new Date(maxD.getFullYear(), maxD.getMonth(), maxD.getDate()),
changeFirstDay: false});
});
But above code not working properly for another local country.... It always pick my system date format "mm/dd/yyyy".
So I try to format the date var dateFormat = "dd.mm.yyyy"; var startDate = "16/05/2012";
dateFormat may varies, for example, dd/mm/yyyy, m/dd/yyyy, dd-mm-yyyy etc.,. based on this startDate should formatted. have any need options other than split by separator?
Upvotes: 1
Views: 766
Reputation: 8552
add jquery ui plugin in your page.
function DateFormate(dateFormate, dateTime) {
return $.datepicker.formatDate(dateFormate, dateTime);
};
Upvotes: 0
Reputation: 3210
I personally use this date formatter which is a ninja of all date formatting.
Upvotes: 1