BrianI Posted March 29 Report Share Posted March 29 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 Quote Link to comment Share on other sites More sharing options...
0 CoopperBackpack Posted March 29 Report Share Posted March 29 Hello @BrianI, You can try the following: let dueDate = new Date('[@field:due_date]'); let today = new Date(); if(dueDate < today){ //do something } However, it is good to know the use case details, because using SQL instead of JavaScript could be possible. BrianI 1 Quote Link to comment Share on other sites More sharing options...
0 BrianI Posted March 29 Author Report Share Posted March 29 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> Quote Link to comment Share on other sites More sharing options...
0 CoopperBackpack Posted March 29 Report Share Posted March 29 @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. Quote Link to comment Share on other sites More sharing options...
0 BrianI Posted March 29 Author Report Share Posted March 29 Thanks it highlights the entire row, my code is working as posted so no need to update. Remove the console.log obviously. Cheers CoopperBackpack 1 Quote Link to comment Share on other sites More sharing options...
Question
BrianI
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
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.