troubleshooting Question

need to validate date time in tabular format

Avatar of puneet kumar
puneet kumar asked on
JavaScriptjQueryJava EE
13 Comments1 Solution138 ViewsLast Modified:
Hi Team,

I have an issue with date time picker. i have 3 date fields that are Pdate,Qdate,bDate , i put the validation while selecting B Date is greater then Q Date and q Date is greater then P Date and B Date is greater then P Date simple you can say that P Date , Q Date and B Date is in increasing order when i am taking date picker it's working fine but when i am using the date time picker its comparing each column time separatly and checking the time also in increasing order but i want only date compare my code is below please check and let me know if you need more clarification . please help me out on my below code where
i m doing wrong.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<script src=""></script>

    function validateDates() {
	 //get values of dates
	 var array = [];
	 var error = false;
	 $(".chkValues:checked").each(function() {
	   var parent = $(this).closest('tr');
	   var last = 0;
	   //var lbl = ['Pdate','PPDate','Bdate'];
	   var lbl = ['Pdate','QDate','Bdate'];
	   $('.date', parent).each(function(i, e) {
	     var dt = new Date(e.value.split("/").reverse().join("-"));
	     if (dt.getTime() <= last) {
	    	 alert(lbl[i] + ' date must be greater than ' + lbl[i-1] + ' date');
	     last = dt.getTime();
	   $row = $(this).data('row'); //row1, row2, row3 etc
	   $('input.' + $row).each(function() {
	 return error ? [] : array;
	$(document).ready(function() {
	   const array = validateDates();
	   if (array.length === 0) {
	     //alert("Some issue with dates");
	     type: "POST",
	     url: "Test.jsp",
	     data: {
	    	 array : array 

	     success: function(responseFromServer) {
	       $.each(responseFromServer, function(resultMessageKey, resultMessageValue) {
	     error: function() {
	       alert(" Ajax call Failed to Update Values  into Database ");

		 format:'d/m/Y H:i'

	 $('.chkValues').on('click', validateDates);
    <form action="" id="myForm" method="post">
  <table id="tableData" width="100%" name="tableData">
      <th>P Date</th>
      <th>Q Date</th>
      <th>B Date</th>
      <td><INPUT type="checkbox" data-row="row" class="chkValues" name="chkBox" value="" size="50"/></td>
      <td align="left"><input class="inputText row0" type="text" name="mYear" id="mYear0" value="1-2020"></td>
      <td><input class="date row0" id="pDate0" name="dob" type="text" value="24/01/2020 12:50" /></td>
      <td><input class="date row0" id="qDate0" name="dob" type="text" value="26/01/2020 10:50" /></td>
      <td><input class="date row0" id="bDate0" name="dob" type="text" value="28/01/2020 09:40" /></td>
      <td><INPUT type="checkbox" data-row="row" class="chkValues" name="chkBox" value="" size="50"/></td>
      <td align="left"><input class="inputText row1" type="text" name="mYear" id="mYear1" value="2-2020"></td>
      <td><input class="date row1" id="pDate1" name="dob" type="text" value="20/02/2020 08:50" /></td>
      <td><input class="date row1" id="qDate1" name="dob" type="text" value="22/02/2020 11:25" /></td>
      <td><input class="date row1" id="bDate1" name="dob" type="text" value="24/02/2020 05:15" /></td>
      <td><INPUT type="checkbox" data-row="row" class="chkValues" name="chkBox" value="" size="50"/></td>
      <td align="left"><input class="inputText row2" type="text" name="mYear" id="mYear2" value="3-2020"></td>
      <td><input class="date row2" id="pDate2" name="dob" type="text" value="24/03/2020 02:35" /></td>
      <td><input class="date row2" id="qDate2" name="dob" type="text" value="26/03/2020 22:45" /></td>
      <td><input class="date row2" id="bDate2" name="dob" type="text" value="28/03/2020 20:15" /></td>
  <input id="btnSubmit" type="submit" value="submit" />
Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros