Jump to content
  • 0

Compare date field to today in Java


BrianI

Question

Hi, I have a date field called duedate it is set to 3/30/2024, using the below code....

console.log([@field:due_date*]);

Returns: 0.00004940711462450593

I'm not sure what this format is? It's not a timestamp I'm familiar with. I'd like to compare it to today....

var today = new Date();

if(duedate < today)

How do I convert the duedate?

 

Thanks

 

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Thanks

That is where I started but I guess I must have had some sort of syntax issue it is working now. Full code...

<a id="visi[@field:task_id]"></a>

<script>
     var isi = document.getElementById("visi[@field:task_id]");
     var today = new Date();
     var duedate = new Date('[@field:due_date*]');

     console.log('today:' + today + ' duedate: ' + duedate);

     if(duedate < today){
          isi.parentNode.parentNode.style.backgroundColor = "#FFC0CB";
     }
</script>

Link to comment
Share on other sites

  • 0

@BrianI

As far as I understand, you need to apply the background color for a row on the Results page of the Report. 

I shared a solution for this case in this forum post 

The solution is to highlight the cell with the date.

If you want to highlight the whole row, a small change is needed:
 

<script>
document.addEventListener('DataPageReady', colorHandler)

function colorHandler() {

  const dateField= document.querySelectorAll('td:nth-child(2)'); // 2 is the Date field position on the results page
    
  const date = new Date();
  
  const todayDay = `${date.getDate()}`.padStart(2, 0);
  const todayMonth = `${date.getMonth() + 1}`.padStart(2, 0);
  const todayYear = date.getFullYear();
  
  const today = Date.parse(`${todayMonth}/${todayDay}/${todayYear}`);
  
  dateField.forEach(element => {
    if (Date.parse(element.innerText) < today) {
      element.parentElement.style.backgroundColor = '#FFC0CB';
      } 
  });

  document.removeEventListener('DataPageReady', colorHandler)
}
    
</script>

 

This should work if the Date field is added to the Results. 

If you don`t add this field, please let me know I will check what should be modified in the code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...