Alvaro
Alvaro

Reputation: 101

Change date format on datepicker

Hi i using this code to show a expiration date based on the select.

<script>    
$(function(){                  
    $("#date_picker").datepicker();
    $("#Plano_Id").change(function() {
        var offset = +$(this).find("option:selected").attr("title"), /* get days to add on date*/
        theDate = new Date();
        theDate.setDate(theDate.getDate() + offset);         
        $("#date_picker").datepicker("setDate", theDate);
    });    
});        
</script>

But this returns the date in this format mm/dd/yyyy. I'm trying to show dd/mm/yyyy

Upvotes: 0

Views: 1108

Answers (2)

Robin Maben
Robin Maben

Reputation: 23094

For setting the format for a specific date control

$('#datepicker').datepicker({ dateFormat: 'dd/mm/yyyy' });

For setting it throughout your site/page, use

$.datepicker.setDefaults({ dateFormat: 'dd/mm/yyyy' });
//Note:Call this before initializing any date pickers

Upvotes: 4

Royce Feng
Royce Feng

Reputation: 1663

Use the dateFormat option: http://jqueryui.com/demos/datepicker/#date-formats

Upvotes: 1

Related Questions