JQuery Datepicker returned Date object type

What is the type of object returned by Datepicker? Suppose I have the following:

$("#txtbox").datepicker({ onClose: function(date){ //something } }); 

What is date ? I am interested in reading a date object from another Datepicker for comparison, for example:

  function(date){ oDate = $("#oDP").datepicker("getDate"); if(oDate == date) //do one else if(oDate > date) //do two } 

However, such a comparison does not work. I assume there is some sort of comparison method for the Date object, but I don't know. I also tried to compare string representation of dates like oDate.toString() > date.toString() no avail.

+4
source share
4 answers

I just downloaded the source from here and noticed (ex line 600) the author uses .getTime () to compare dates, have you tried this?

 if (oDate.getTime() > date.getTime()) { ... } 

This is also true, but you mentioned that you tried to use oDate.toString (), while I noticed in the examples the author uses .asString ()

+7
source

The Date object is returned by datePicker .

Your date comparison method is valid - from W3schools :

 var myDate=new Date(); myDate.setFullYear(2010,0,14); var today = new Date(); if (myDate>today) { alert("Today is before 14th January 2010"); } 

Are you getting the value in oDate from this line?

 oDate = $("#oDP").datepicker("getDate"); 

Your comparison method seems valid - so I wonder if datePicker successfully pull a value from #oDP ?

Edit - oDate confirmed that it contains a valid date. This may be a very stupid question, but have you confirmed that Date contains a valid date? I am wondering if there could be a problem with naming it in the same way as the Date keyword ( Javascript keywords and reserved words ). Perhaps try renaming it to tDate or the like in your function to be twice as clear that this is not a problem.

+5
source

Use this to compare dates, it works: $ ("# datepickerfrom"). datepicker ("getDate") <$ ("# Datepickerto"). DatePicker ("GetDate")

0
source

What is a date?

this is an object of $ ("# txtbox")

-2
source

Source: https://habr.com/ru/post/1277334/


All Articles