1

I apologise if this is a really basic question but I am using the following jquery plugin: http://jonathanleighton.com/projects/date-input

I want to change the date from YYYY-MM-DD to DD/MM/YYYY using his suggestion under customisations. I tried to do the following which I thought would work but it completely breaks it:

$.extend(DateInput.DEFAULT_OPTS, {
  stringToDate: function(string) {
    var matches;
    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
      return new Date(matches[1], matches[2] - 1, matches[3]);
    } else {
      return null;
    };
  },

dateToString: function(date) {
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return date.dom + "/" + month + "/" + getFullYear();
  }
});

It's the following line where it all goes wrong:

return date.dom + "/" + month + "/" + getFullYear();

Could anyone offer a suggestion as to what I'm doing wrong?

3
  • try putting the return value into a variable and then return it Commented Apr 21, 2011 at 15:28
  • Are you getting any error messages? Commented Apr 21, 2011 at 15:36
  • What is it doing? What's the error? Commented Apr 21, 2011 at 15:39

2 Answers 2

2

You should try using the jQuery UI datepicker. Very easy to format the date

http://jqueryui.com/demos/datepicker/

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

1 Comment

Thanks I think I'll just use that as it will be much easier than trying to debug this code.
0

i don't think you need the "date" in date.dom:

try replacing this:

return date.dom + "/" + month + "/" + getFullYear();

with this:

return dom + "/" + month + "/" + getFullYear();

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.