JQuery Datepicker - onSelect Date Format

8.8k views Asked by At

Using this:

$(function () {
    $("#datepicker").datepicker({
        onSelect: function (date) {
            var links = "http://google.co.uk/";
            window.location.href = links + date;
        }
    });
});

To populate a URL - unique for each day picked from the datepicker.

In this case - Google.co.uk used as an example with the data appended.

I would like to change the date format to be "ddmm" - so that clicking on 2nd January (and year) returns the link: http://goolge.co.uk/0201.

I can't figure out how to change the default data formatting from mm/dd/yyyy.

Example code here >>> JSFIDDLE

2

There are 2 answers

1
Spokey On BEST ANSWER
$(function () {
    $("#datepicker").datepicker({
        dateFormat: 'ddmm',
        onSelect: function (date) {
            var links = "http://google.co.uk/";
            window.location.href = links + date;
        }
    });
});
0
NimueSTEM On

Thanks for the feedback.

I've integrated the answers into http://glengilchrist.co.uk/hwb/numday.html

The datepicker throws out the ddmm date format, which is wrapped into a full URL.

This then pushes to a site containing 366 Maths activities.

(Very rough, with not formatting)

Cheers G