0

I am using a bootstarp datepicker :DatepickerLink

but I need to change the format on the basis of a variable ,how to do that?

I am trying to use this code

if (sessionStorage.Dateformat && sessionStorage.Dateformat != '') {
                    dateFormat = sessionStorage.Dateformat;

                }
else{
      dateFormat='dd-M-yyyy';
}

////////////////////////////////////////////////////////

  $('#sand .input-group.date').datepicker({
                    format: dateFormat,
                    todayHighlight: true
                });

but it is saying invalid date format ///////For Information This way is working

 $('#sand .input-group.date').datepicker({
                        format: 'dd-M-yyyy',
                        todayHighlight: true
                    });
4
  • Check format of date-picker (eg: dd-mm-yyyy) and get your input in the same format to not get the error. Commented Dec 11, 2015 at 7:33
  • date format is correct but the it is not taking the way i wan like by setting format:dateFormat where datefomat is a variable Commented Dec 11, 2015 at 7:37
  • Perhaps its taking it as a String. Use Javascript to ensure conversion correct format console.log output and paste here. Also I am not sure dateFormat='dd-M-yyyy' actually exists. One thing is for sure the format you are passing is not the correct format, so mess around with that and things will work out. Commented Dec 11, 2015 at 7:44
  • But I am damn sure it is correct as i worked on that from last 1 week its a plugin where we use this format to set date like 12-Dec-2015 Commented Dec 11, 2015 at 7:49

1 Answer 1

1

the format of your date is incorrect:

{
  dateFormat='dd-mm-yyyy';
}
Sign up to request clarification or add additional context in comments.

3 Comments

its a correct format i have checked that one by giving manually
the dateformat = dd-M-yyyy does not exist. can you post a detailed error log?
have you check the link there you can see the date format is working its a plugin where 12-Dec-2014 is given in dd-M-yyyy

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.