07 July 2009

Replacing Time field

SharePoint provides date time field in a fixed format, However we can further organized to have a hourly/minute counter to view its last updates/modification.
This can be achieved by using a simple Content Editor Web part[CEWP] and Script for converting "DD/MM/YYYY hh:mm" to minutely incremental field.

Add the following sniplet in the source script section fo the CEWP.

<--Code-->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var str = "Last Updated"; //change
this based on col header

var today = new Date();
today = Date.parse(today)/1000;
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 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 dd = (today-d1)/86400;
var dh = (dd-Math.floor(dd))*24;
var dm = (dh-Math.floor(dh))*60;
var time = ((Math.floor(dd) > 0 ? Math.floor(dd) +" days, " : "")+
(Math.floor(dh) > 0 ? Math.floor(dh)+" hrs, " : "")+
(Math.floor(dm)+" min"));
$(e).text(time);
});
});
</script>
Special Thanks: Paul Grenier


2 comments:

  1. Is this solution works on SharePoint 2010 also

    ReplyDelete
    Replies
    1. Yes This works on Sharepoint 2010. when tagged in page as html

      Delete

Thanks for your valuable comments

Rate Now: