Highlight row if more than 1 day old

Joined
Mar 12, 2023
Messages
5
Reaction score
0
Hi all.

I am trying to highlight a row in a database if it's more than 1 day old,

I'm trying this, but it's making all the dates highlighted.

TIA
Pat

Code:
$j(function(){
            
      $j('.louth-entereddate').each(function(){
        var today = new Date();
                if(d.setDate(d.getDate() - 1){
            $j(this).parents('tr').addClass('warning');
        }


      })
    })
 
Joined
Mar 5, 2023
Messages
8
Reaction score
3
Hi Pat,

The issue with your code is that you're not fetching the date value for each row and comparing it with today's date. Instead, you're just creating a new date object and comparing it with yesterday's date which is causing all dates to be highlighted.

You need to fetch the date value from the row and compare it with today's date after subtracting one day from it. Here's an updated code snippet for you:

Code:
$j(function(){
    $j('.louth-entereddate').each(function(){
        var enteredDate = new Date($j(this).text()); //fetch date value from row
        var yesterday = new Date(today.getTime() - (24 * 60 * 60 * 1000)); //subtract one day from today's date
        if (enteredDate < yesterday) { //compare date values
            $j(this).parents('tr').addClass('warning');
        }
    });
});
This code will fetch the date value from each row and compare it with today's date after subtracting one day. If the entered date is more than one day old, it will add the `warning` class to the parent row and highlight it.

Let me know if you have any questions!
 
Joined
Mar 12, 2023
Messages
5
Reaction score
0
Still not working,
I'm trying this


Code:
    $j(function() {
        $j('.louth-entereddate').each(function() {
            var d = $j(this).text().split("/");
            entereddate = new Date(d[2] + '/' + d[1] + '/' + d[0]);
            var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
            if (entereddate < yesterday) {
                $j(this).parents('tr').addClass('warning');
            }
        });
    });
 
Joined
Sep 4, 2022
Messages
129
Reaction score
16
hello ! I have a question ( 3 by the way )

"if it's more than 1 day old" means 'not today' ?

'today' display is different ?
or your requirement is "today and yesterday" have a different display ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,747
Members
45,545
Latest member
rapter____0

Latest Threads

Top