0

Based on this link

This where I will go if i wanna change my date format

defaults: {
    formatDate: function(date) {
        var formatted = $.datePicker.utils.pad(date.getDate(), 2) + '/' + $.datePicker.utils.pad(date.getMonth() + 1, 2) + '/' + date.getFullYear();
        return formatted;
    },
    parseDate: function(string) {
        var date = new Date();
        var parts = string.match(/(\d{1,2})\/(\d{1,2})\/(\d{4})/);
        if ( parts && parts.length == 4 ) {
            date = new Date( parts[3], parts[2] - 1, parts[1] );
        }
        return date;
    },
    selectDate: function(date) {
        return true;
    },
    limitCenturies: true,
    closeOnPick: true,
    appendTo: null
},

How can I make this to MM/DD/YYYY? I tried everything I change it but when Im selecting dates the value goes on different dates

Here is the error

enter image description here

Nardong Bagsik
  • 218
  • 6
  • 20

2 Answers2

1

According to the documentation, this should work:

    defaults: {
        formatDate: function(date) {
    //var formatted = $.datePicker.utils.pad(date.getDate(), 2) + '/' + $.datePicker.utils.pad(date.getMonth() + 1, 2) + '/' +  date.getFullYear();
            var formatted = $.datePicker.utils.pad(date.getMonth() + 1, 2) + '/' + $.datePicker.utils.pad(date.getDate(), 2) + '/' + date.getFullYear();

            return formatted;
        },
        parseDate: function(string) {
            var date = new Date();

            if ( string ) {
                formatted_date = string.split('/');
                date = new Date( formatted_date[2], formatted_date[0] - 1, formatted_date[1] );
            }

            return date;
        },
        selectDate: function(date) {
            return true;
        },
        limitCenturies: true,
        closeOnPick: true,
        appendTo: null
    }

See it in action: Demo.

cabrerahector
  • 3,653
  • 4
  • 16
  • 27
0

Try this out

var date = new Date('2014-01-06');
var newDate = date.toString('dd-MM-yy');
joepil
  • 51
  • 1
  • 12