1

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?

1
  • 1
    Any chance you could rephrase this question? I am very unclear on what you're asking here. Commented May 16, 2012 at 13:54

4 Answers 4

1

You can try the Datejs library.

Sign up to request clarification or add additional context in comments.

Comments

1

jQuery dateFormat is a good plugin to use for this.

2 Comments

I try but I dont How to use.... try below code $.format.date("2009-12-18 10:54:50.546", "dd/MM/yyyy"); i am getting error date not define
You have to actually get (and/or load) the plugin. It's not part of the base jQuery package.
1

I personally use this date formatter which is a ninja of all date formatting.

Comments

0

add jquery ui plugin in your page.

function DateFormate(dateFormate, dateTime) {
    return $.datepicker.formatDate(dateFormate, dateTime);
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.