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.


<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"
$.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)"
$.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"));
Special Thanks: Paul Grenier


  1. Is this solution works on SharePoint 2010 also

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


Thanks for your valuable comments

Rate Now: