Does anybody know a way of showing days past on view (rendering of a page), since the day an item was created.

I need this number for other calculations, to color format some usefull output.

I see a lot of example, mainly telling that [today] / today() can't be used for that in calculated columns, some work around that require the item to be modified, but that's not what i want, i like to show, when items are not modified. and people are late to respond i need to show that.

--update-- This problem seams a bit more complex then i originally thought. As i wrote i want to see how long it takes before people respond. There's a status(text) and modified(date) column, once text changes to it should stop counting, and preferably another column starts to counting between status assigned and status closed. (modified date might not be the best indicator for this is the status column, as modified might not always work(people need to have opened it). FYI there is also another column with a closed date, and closed is a status as well, so closed date could be retrieved from it.

Therefore i think client side rendering would not solve this. Yes those scripts work to so show days since, but at some point they should stop counting, i dont think i could do that with client side rendering

So i think i should do some kind of server side powershell script, and schedule it to run each day at 00:01 (not the best option perhaps but right now i dont know other solutions to this).

  • Look for workarounds using JSLink – Erin L Jun 1 '16 at 14:58
  • I would look into using JS Link and client-side rendering. – Rothrock Jun 1 '16 at 14:58
  • Would such a thing be possible using a daily scheduled powershell script ?, to silently change day since created in a column. (without server triggering workflows, or changing modified date). then its a real number and more calculations can be done with it – Peter Jun 1 '16 at 15:02
  • On-prem, sure, you'd have the full SSOM to take advantage of and be able to do a system.update to recalc anything you'd like. – Eric Alexander Jun 1 '16 at 17:33
  • As for your update, client side rendering can still be used. You just have to an include an if statement in your javascript to check whether to display days since a field (while still counting) or days between two fields (after done counting). – Erin L Jun 2 '16 at 14:12

Try this.

Create one Calculated column and set data type return from formula as Number. Apply below formula:

="<img src='/_layouts/images/blank.gif' onload=""{"&" var day=new Date();"&" var SPday=new Date(); "&"  SPday.setFullYear("&YEAR(Created)&","&MONTH(Created)-1&","&DAY(Created)&");"&" var m = Math.ceil(Math.abs(SPday.getTime()-day.getTime()) /(1000*3600*24)); "&" this.parentNode.innerHTML= m ;"&"}"">"

Here it will show the days difference between Created and today's date and it will be updated everyday ;)

You can pass your desired date column. Hope this will help you!

  • First of all thanks, been looking for this a long time, later though it seamed not possible to build a solution around it, see my update in the problem – Peter Jun 2 '16 at 7:08

As is mentioned in the comments, I would highly recommend doing this through Client Side Rendering. SharePoint provides a very handy built in JavaScript function GetDaysAfterToday(date) which you could use to get the result you want very easily.

GetDaysAfterToday would return a negative number for dates occurring in the past, so you would have to do something like this

var createdDate = new Date(ctx.CurrentItem.Created);
var daysSinceCreated = GetDaysAfterToday(createdDate);
daysSinceCreated = Math.abs(daysSinceCreated);

to get a positive number, but then you can use that number to control whatever conditional formatting you want.

Keep in mind that you will have to include the Created date column in the view in order for this to work.


To respond to your comment: I would have used this code in a field override script, using the Client Side Rendering framework. Check out this page to learn more about CSR and how it works. Basically I would have put this code, along with some other code necessary to hook into the CSR framework, in a JavaScript file and uploaded it to the site (I tend to put them in a "Scripts" folder in the Site Assets library). Then I would have linked to the script either through the JSLink property of the field I wanted to override (would need to use Powershell to set that), or through the JSLink property of the List View Web Part (through the web part's editor pane).

To address your update to the original question: yes, your problem seems much more complicated than you originally stated. CSR may not be the best way to do all that (although you could probably figure out how, I have done some pretty complicated stuff using CSR scripts). As Eric Alexander said in his comment, since you are on-prem, you can leverage the Server-Side Object Model to help achieve what you want.

  • although (see problem update) i dont think i can use client side rendering. i wonder how would you have used your code, in a script web part, or somehow in a calculated column ?. – Peter Jun 2 '16 at 7:11
  • @user3800527 updated my answer. – Dylan Cristy Jun 2 '16 at 13:21
  • Thanks for your information, my script is almost ready. Its quite large. I've put even more logic into it now, so i need less calculated tables. I only wonder if i would have written in C# if it would have been faster then powershell, i guess so, but extending a basic script with my logic was quite easy i found. – Peter Jun 3 '16 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.