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)
?
Set changeMonth and changeYear to true so that Month and Year appear as Dropdown. Set date format to "MM yy". jQuery DatePicker has "onClose" event, which is called when Datepicker gets closed. So using this event, fetch the selected Month and Year and setDate of Datepicker.
inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });
Do one of the following: For a text box control or a date picker control, ensure that the Data type list displays the appropriate data type, and then click Format. For an expression box control, ensure that the Format as list displays the appropriate data type, and then click Format.
Set Current Date in DatePicker using jQueryvar now = new Date(); var day = ("0" + now. getDate()).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With