I have managed to automatically build an HTML table based on a output from my ERP system, and managed to use CSS to format it easily. The last step is conditional formatting in a Date Field. If the date is < from now make the field RED if it's between 4 <> 7 days from NOW make it YELLOW else "no formatting.
I have gotten this far on dozens of examples from this site, and I am hoping you can help me do some basic DATE MATH which for some reason I just can't get my head around.
Right now my date field is in the td:nth-child(4) and I want to compaire it to the current date.
    <script>
    $(document).ready(function() {
            $('table td:nth-child(4)').each(function() {
                var D1 = $(this).text();
                var D2 = new Date();
                if ((D1 - D2) < 4) {
                    $(this).css('backgroundColor', 'RED'); 
                }
                else if((D1 - D2) < 7) && ((D1 - D2) > 4) {
                    $(this).css('backgroundColor', 'YELLOW'); 
                }
                else {
                    $(this).css('backgroundColor', '#99faa0'); 
                }
            });
            event.preventDefault();
    });
    </script>
 
     
    