How to get date, month, year in jQuery UI datepicker?

datepicker, jquery, jquery-ui

Solution

You can use method getDate():

$('#calendar').datepicker({
    dateFormat: 'yy-m-d',
    inline: true,
    onSelect: function(dateText, inst) { 
        var date = $(this).datepicker('getDate'),
            day  = date.getDate(),  
            month = date.getMonth() + 1,              
            year =  date.getFullYear();
        alert(day + '-' + month + '-' + year);
    }
});

FIDDLE

Problem

I have this sample code: ``` <div id="calendar"></div> $(document).ready(function() { $('#calendar').datepicker({ dateFormat: 'yy-m-d', inline: true, onSelect: function(dateText, inst) { var month = dateText.getUTCMonth(); var day = dateText.getUTCDate(); var year = dateText.getUTCFullYear(); alert(day+month+year); } }); }); ``` When I run the code, there is an error. How to get this `(date, month, year)`?

Original source

Related problems