OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JavaScript comparing two dates input fields

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Guest
I have two date fields the first one is store in MSSQL database known as leavingDate the second is a date picker in the form where user have to select a date.

I need to make sure the selectedDate is not greater than the leavingDate but nothing seems to work.

I have formatted both dates to string and comparing them as follows:

Code:
leavingDate = '2023/11/30
selectedDate = '2023/12/29 //This is wrong

if(selectedDate > leavingDate)
{
   //do something because the date selected is greater.

}

Some of the selected dates works some don't so how do I make sure that the JS always works when comparing two dates (one from database and one from input fields using moment.js)

<p>I have two date fields the first one is store in MSSQL database known as leavingDate the second is a date picker in the form where user have to select a date.</p>
<p>I need to make sure the selectedDate is not greater than the leavingDate but nothing seems to work.</p>
<p>I have formatted both dates to string and comparing them as follows:</p>
<pre><code>leavingDate = '2023/11/30
selectedDate = '2023/12/29 //This is wrong

if(selectedDate > leavingDate)
{
//do something because the date selected is greater.

}
</code></pre>
<p>Some of the selected dates works some don't so how do I make sure that the JS always works when comparing two dates (one from database and one from input fields using moment.js)</p>
 
Top