4

I am using JQueryUI datepicker. I am currently using following:

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

to get date from the datepicker. This function by default gets me today's date if the user has not selected any date in the picker. Is there some function which gets the date the user has selected? For example, if the user has selected today's date, the function should return today's date. If he didnt select any date, then this function should return false, perhaps.

I want this function for validation of date ranges in JQueryUI daterangepicker which currently it is not supporting.

2
  • Since this is about a plugin for datepicker, the question should probably be renamed something like "getting date from Date Range Picker jQuery-ui plugin" Commented May 20, 2010 at 5:53
  • I realize this is an old question, but I am running into this same problem. "getDate" is supposed to return null if nothing selected, but is returning current date for some reason. Create empty datepicker object, no properties, still always returns current date. Did you ever solve this problem? Commented Jul 28, 2014 at 4:48

2 Answers 2

2

See the jQuery UI docs. In code:

.datepicker("getDate");

Returns the current date for the datepicker or null if no date has been selected. I just ran this method on the demo box provided on the jQuery UI docs. Text from firebug console:

[no date set]

>>> $("#datepicker").datepicker("getDate");
null

[I then set the date to tomorrow using the datepicker]

>>> $("#datepicker").datepicker("getDate");
Tue Apr 06 2010 00:00:00 GMT+1200 (New Zealand Standard Time) {}

Is this what you are after?

Sign up to request clarification or add additional context in comments.

Comments

1

The daterangepicker is made up of two datepickers that get automatically generated. The start date datepicker has the class "range-start" and the end datepicker has "range-end".

Thus, accessing the getDate functions is pretty straightforward:

$(".range-start").datepicker("getDate");
$(".range-end").datepicker("getDate");

Tested in Firefox, worked for me perfectly. Great plugin btw!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.