Jump to content

Show icon based on time difference


Recommended Posts

Lets say you have two date fields called Date1 and Date2 also a unique field for each row called Id
 

<div id="show[@field:Id]"></div>
<script>
var d1 = new Date('[@field:Date1]');
var d2= new Date('[@field:Date2]');

var hourDiff =d2 - d1;

var minDiff = hourDiff / 60 / 1000;

if (minDiff  < 30){
document.getElementById('show[@field:Id]').innerHTML = '<img src="http://someapp.com/nk/icons/greenstar.png" width="100px"/>';
}
else if (30<minDiff && minDiff <120 ){
document.getElementById('show[@field:Id]').innerHTML ='<img src="http://someapp.com/nk/icons/redstar.jpe" width="100px"/>';
}else if (minDiff >120){

document.getElementById('show[@field:Id]').innerHTML ='<img src="http://someapp.com/nk/icons/yellowstar.jpe" width="100px"/>';

}

</script>

 

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
Reply to this topic...

×   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...