Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table in an html file with a 'delivery name' and'date expected' column.

------------------------------
Delivery Name | Date Expected
------------------------------
ARR | 5/23/2018
ND | 11/3/2019
VAANN | 1/29/2017

I would like for an alert to pop up and list the delivery name if the associated date is 30 days past due.

----------------------------
Alert!
VAANN is 30 days past due!
ARR is 30 days past due!
----------------------------

What I have tried:

JavaScript
var d = new Date();
var momentDate = moment(d);
var date = moment(d).format('M/DD/YYYY');
console.log(date);


$(function  () {

  $('p').each(function (index, element) {
    var $element = $(element);
      formatted = moment($element.text(), 'M/D/YYYY').format('M/D/YYYY');
      console.log(formatted);
    $element.text(formatted);

  })

});
Posted
Updated 29-Sep-18 4:57am

1 solution

Not sure why are you using format while you need to compare dates, you should compare the date value to check if the due date is missed by 30 days

JavaScript
var datePast30Days = moment().subtract(30, days);


$(function  () {

// this could be any selector for your due date col like $('p.col-due-date')
  $('p').each(function (index, element) {
    var $element = $(element);
    var dueDate = moment($element.text(), 'M/D/YYYY');
    
    if(dueDate< datePast30Days) {

     // add your alert logic here, you can pass these values to a function or can append it to your alert box;

    }

  })

});


for details read moment docs @ Moment.js | Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900