Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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)?

like image 970
Vy Pham Avatar asked Apr 24 '13 07:04

Vy Pham


People also ask

How do you only show month and year in date picker?

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.

How can change date format in jQuery ui datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change date format in picker?

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.

How can I get current date in datepicker?

Set Current Date in DatePicker using jQueryvar now = new Date(); var day = ("0" + now. getDate()).


Video Answer


1 Answers

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

like image 155
Eli Avatar answered Sep 22 '22 12:09

Eli