user3228992
user3228992

Reputation: 1373

set right dateformat with jquery datepicker

I'm trying to set the the date format to 'dd-mm-yy'

Here is my script, but this doesn't seem to work. It still displays the standard 'mm-dd-yy'

What I'm I doing wrong. Here is my script:

<script>
    $(function () {
        $("#datepickerStartDate").datepicker();
        $("#format").change(function () {
            $("#datepickerStartDate").datepicker({ dateFormat: 'dd-mm-yy' }).val();
        });
    });
</script>

Upvotes: 1

Views: 102

Answers (2)

Tats_innit
Tats_innit

Reputation: 34107

Working demo here or Demo 2 working here

I have added html and the sample, if you strictly aim for dd-mm-yy the checkout another SO link below.

Hope rest help your need :)

code sample

$(function(){

    $('#thedate').datepicker({
        dateFormat: 'dd-mm-yy',
        altField: '#thealtdate',
        altFormat: 'yy-mm-dd'
    });
});

enter image description here

Upvotes: 1

RichardBernards
RichardBernards

Reputation: 3097

I believe you are looking for this:

<script>
    $(function () {
        $("#datepickerStartDate").datepicker();
        $("#format").change(function () {
            $( "#datepickerStartDate" ).datepicker( "option", "dateFormat", 'dd-mm-yy' );
        });
    });
</script>

After your comment, I think you are actually looking for this:

<script>
    $(function () {
        $("#datepickerStartDate").datepicker({ dateFormat: "dd-mm-yy" });
    });
</script>

If not, please let me know exactly what you want to achieve with which html-elements.

Upvotes: 0

Related Questions