You are viewing limited content. For full access, please sign in.

Question

Question

check if start_date is bigger than end_date in table

asked on March 15, 2019 Show version history

I have a table has two columns start_date and end_date with format dd/MM/yyyy, end_date value came from lookup from DB. need to alert user if he select start_date later than end_date. and also if end_date is empty he can not select start_date.

here what i tried but it is not working.

CheckDate();
  $('.tbl3').on('change', CheckDate);
  function CheckDate() {
    $('.tbl3 tbody tr').each(function () {
      $(this).find('.start_date input').each(function () {
        var start_date = $(this).closest('tr').find('.start_date input').val();
        var end_date = $(this).closest('tr').find('.end_date input').val();

        //convert to standard date format like YYYY-MM-DD
        start_date = 
          start_date.split('/')[2]+"/"+start_date.split('/')[1]+"/"+start_date.split('/')[0]

        end_date = 
          end_date.split('/')[2]+"/"+end_date.split('/')[1]+"/"+end_date.split('/')[0]
        if (Date.parse(start_date) > Date.parse(end_date))
        {
          error = true;
          alert('Start Date is later than End Date');
        }
        else
        {
        }

      });
    })
  }

 

0 0

Replies

replied on March 18, 2019

Here are a couple posts that might help get you started

https://answers.laserfiche.com/questions/148461/How-to-write-JavaScript-with-date-comparisons#148473

https://answers.laserfiche.com/questions/107606/Date-comparison-calculation-when-one-date-is-in-a-table#107709

There might be others as well if you try to search for date comparisons using Javascript. 

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.