0

I have this code where it normally displays all of the number of rows on database. Is there a way to compare the returned date(Promised Date) to javascript or jquery so i can highlight all of the dates that are less than 3 days from the today's date. Thanks

<div class="container">
  <table id="requirement_table" class="table table-bordered table-hover table-sm" style="width:100%">
    <thead>
      <tr>
        <th>Applicant Name</th>
        <th>Requirement</th>
        <th>Remarks</th>
        <th>Promised Date</th>
        <th>Completed</th>
      </tr>
    </thead>

    <tbody>
      {% for req in app_requirements %}
      <tr>
        <th>{{ req.applicant }}</th>
        <th>{{ req.requirement }}</th>
        <th>{{ req.remarks }}</th>
        <th>{{ req.date_promised }}</th>
        <th>{{ req.completed }}</th>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>
michael ababao
  • 145
  • 2
  • 11
  • Yes, but can't help you much without seeing how the date is returned. Convert it to javascript date object and compare it with whatever date you need. – Cray Apr 29 '19 at 05:17
  • @cray. the date is returned like this Dec. 16, 2019 tried to compared it to string and it matched. How can i convert it to javascript or jquery date object? – michael ababao Apr 29 '19 at 05:19
  • [Tutorial](https://stackoverflow.com/questions/5619202/converting-a-string-to-a-date-in-javascript) for converting string to date. However yours is not in ISO format. If you can't change that use a library as the link states or convert it to ISO format using javascript. I see that you can split string on `.` and `,` to get 3 pieces and then you should change the month name to numeric value. – Cray Apr 29 '19 at 05:24
  • Seems that JS can actually accept your format aswell. Try `Date.parse(yourDateHere);` and see if it works for you. – Cray Apr 29 '19 at 05:29
  • Wow thanks. the Date.parse works for me. Can you post your answer so i can approve it. – michael ababao Apr 29 '19 at 05:47

1 Answers1

0

Convert String to Date object and compare it with the date you need.

let myDate = getDateSomewhere();
Date.parse(myDate);
Cray
  • 2,774
  • 7
  • 22
  • 32