AfternoonHere is the code I am working with.As you can see, the code displays the days left for a job to go, as well it shows when things are overdue.However, it is not working right - what I need to be able to do is show "Due Today" when the date is today, then when it passes the date, it says "Overdue", otherwise it will just show the days left.One other thing, when there is 1 day left, it shows 1 Days - I would like it to show 1 Day.Any help would be appreciated.Iain $(document).ready(function(){ var str = "Time Left"; //change this based on col header var a=0; var headers = $("table.ms-listviewtable:first> tbody> tr:first th").get(); $.each(headers, function(i,e){ x = $(e).contents().find("a[title*='"+str+"']").length; a = x > 0 && i > a ? i : a; }); var today = new Date(); today = Date.parse(today)/1000; var dArray = $("table.ms-listviewtable:first> tbody> tr:gt(0)").find(">td:eq("+a+")").get() $.each(dArray, function(i,e){ var d1 = Date.parse($(e).text())/1000; var time = '<span style="color:#ff0000">Overdue</span>'; if(d1-today > 0) { // calculate days, hours, minutes and seconds var dd = (d1-today+86400)/86400; var dh = (dd-Math.floor(dd))*24; var dm = (dh-Math.floor(dh))*60; var ds = (dm-Math.floor(dm))*60; // build display string time = ((Math.floor(dd) > 0 ? Math.floor(dd) +"d " : "")+ (Math.floor(dh) > 0 ? Math.floor(dh)+"h " : "")+ (Math.floor(dm) > 0 ? Math.floor(dm)+"m " : "")+ (Math.floor(ds) > 0 ? Math.floor(ds)+"s" : "")); // highlight active auctions var isEndingSoon = (((Math.floor(dd) + Math.floor(dh)) <= 0) && (Math.floor(dm) < 15)) ; if(isEndingSoon) { time = '<span style="color:#ffcc00">' + time + '</span>'; } else { time = '<span style="color:#005a04">' + Math.floor(dd) + " days " + '</span>'; } } // write out text value as html $(e).text('<span style="font-weight:bold">'+time+'</span>'); $(e).html($(e).text()); }); });
For the day/days problem, change else { time = '<span style="color:#005a04">' + Math.floor(dd) + " days " + '</span>'; } Code (markup): to else { time = '<span style="color:#005a04">' + Math.floor(dd)+ " day"; if (Math.floor(dd) != 1) time += "s"; time += ' </span>'; } Code (markup):
Hi RukbatThis works great - thank you for that.Now I just need to figure out / fix the other problem which is say forthe code to say Due to day when the date hits zero - I will play with the code you sent me to see if I can do something with it.Thanks again for you help.Iain
Check the date in the database. In most cases, if no time is specified, a date is just after midnight on that date. If you're subtracting a date that's being interpreted as "almost midnight", two dates that look the same may give a difference of 1 day. Do a few tests to see exactly how your code is interpreting things.