How to get date with jQuery UI datepicker

I want to get a date with datepicker whenever a user selects a date in jQuery UI datepicker and clicks a button on the form.

Well, I need to get the day, month, and year of the date picker. How can I get jQuery UI date form?

+84
javascript jquery jquery-ui
Feb 07 2018-11-11T00:
source share
6 answers

Using

$( your_datepicker_id ).datepicker( "getDate" ) 
+125
Feb 07 '11 at 9:52
source share

You can get the date using the getDate function:

 $("#datepicker").datepicker( 'getDate' ); 

The value is returned as a JavaScript date object.

If you want to use this value when the user selects a date, you can use the onSelect event:

 $("#datepicker").datepicker({ onSelect: function(dateText, inst) { var dateAsString = dateText; //the first parameter of this function var dateAsObject = $(this).datepicker( 'getDate' ); //the getDate method } }); 

The first parameter is in this case the selected Date as String. Use parseDate to convert it to a JS Date object.

See http://docs.jquery.com/UI/Datepicker for a full reference to jQuery UI DatePicker.

+84
Feb 07 2018-11-11T00:
source share

Try it, it works like a spell, sets the date you chose. onsubmit try to get this value: -

 var date = $("#scheduleDate").datepicker({ dateFormat: 'dd,MM,yyyy' }).val(); 

Link here

+19
Feb 01 '14 at 2:27
source share

getdate link: http://docs.jquery.com/UI/Datepicker#method-getDate

 $("#datepicker").datepicker( 'getDate' ); 
+4
Feb 07 2018-11-11T00:
source share

Sometimes a lot of trouble with him. In the attribute, the value of the data is data data 06/28/2014, but the datepicker shows either today or nothing. I solved it this way:

 <input type="text" class="form-control datepicker" data-value="<?= date('dm-Y', (!$event->date ? time() : $event->date)) ?>" value="<?= date('dm-Y', (!$event->date ? time() : $event->date)) ?>" /> 

I added a datapicker attribute data value to the input, because if jQuery (this) .val () OR OR jQuery (this) .attr ('value') is called, nothing works. I decided to run a loop in each datapicker and take its value from the attribute data value:

  $("form .datepicker").each(function() { var time = jQuery(this).data('value'); time = time.split('-'); $(this).datepicker('setDate', new Date(time[2], time[1], time[0], 0, 0, 0)); }); 

and it works fine =)

+1
May 20 '14 at 19:24
source share

NamingException answer worked for me. Besides what I used

var date = $("#date").dtpicker({ dateFormat: 'dd,MM,yyyy' }).val()

datepicker did not work, but dtpicker did.

0
Aug 6 '17 at 23:14
source share



All Articles