0

I have a requirement to create a column called Age that tracks how old the current item is.

What this does is that every 24 hours (1 day) the Age column will increase by 1.

For example, if I create a new item today the Age column will display 0. However, 24 hours later the Age column will display 1. And then another 24 hours has passed and the Age column will now display 2 and so on.

This is on SharePoint 2010 List and I'm open to using Designer 2010 but running into logic issues.

If there's a better way, I'm all ears. Thanks.

Gaurravs
  • 3,558
  • 12
  • 22
  • 33
Nina G
  • 935
  • 2
  • 18
  • 40

2 Answers2

2

The best approach to this is to create a timer job or powershell/executable script that runs nightly to query your list items, iterate over them, add 1 to the field, and commit the change using system.update to not affect modified information.

Eric Alexander
  • 43,293
  • 10
  • 53
  • 93
-1

You can create calculated column & use below formula to get the age of the item.

=IF(ISBLANK(Created)
    ,"Created"
    ,"<img src='/_layouts/images/blank.gif' onload=""{"
    &"    var SPday=new Date();"
    &"    SPday.setFullYear("
    &YEAR(Created)
    &","
    &MONTH(Created)-1
    &","
    &DAY(Created)
    &");"
    &" var Days=Math.round((SPday.getTime()-new Date().getTime())/86400000);"
    &"    this.parentNode.innerHTML=((Days<=0)?'':'-') + Math.abs(Days);"
    &"}"">"
  )

It works in my SharePoint 2010 list.

I am sure it will work for you as well. :)

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
Hardik
  • 7,733
  • 2
  • 18
  • 37
  • When can Created be blank for an item ??? – Danny '365CSI' Engelman Jun 17 '16 at 20:02
  • Actually i changed the column name, as it was different in my original code but it is fine i think. :) – Hardik Jun 17 '16 at 20:06
  • Your original code? – Danny '365CSI' Engelman Jun 17 '16 at 20:07
  • I tried the same with my different column, As i was getting the person's age using the Birthday. So i used DOB column inplace of Created in my code. It was one of my task for SP2010. – Hardik Jun 17 '16 at 20:08
  • Do not copy paste information from other SO answers and claim credit, refer people to the answers where you got the information. http://sharepoint.stackexchange.com/search?q=86400000+SPday – Danny '365CSI' Engelman Jun 17 '16 at 20:10
  • I tried the same in my one of the project. If you need than i can attach the photo in the answer. – Hardik Jun 17 '16 at 20:11
  • This is a community, and we help each other out. If we find solutions elsewhere, we credit the author and reference the source. Be nice! – Benny Skogberg Jun 20 '16 at 05:10
  • Don't you think so you are raising the questions on my capabilities? As I already mentioned in above comments that i tried the same in code in my one of the project with different column & So i just posted the same code here even without formatting it. How would i know that someone has already given the answer? Is it all time necessary to find the answer in the community before the posting it? is there any rule? I just posted the answer to help ASPIRE27. Don't you think you guys are being really rude by downvoting it? Sorry to say but I simply lost the trust from this community.. – Hardik Jun 20 '16 at 06:00
  • A. no-one downvoted your anwer, as it is a valid answer. B. I understand you are answering to get points, because I fell for the same gamification psychology. C. anything that does JavaScript in a Calculated Column is 99,9 derived from answers I posted here on SO. D. If you had written your own code you would not have used ((Days<=0)?'':'-') + Math.abs(Days); E. I don't mind you posting code and only care a bit about credit. But do provide complete answers. Your current post does not mention a change of dataType is needed has no explanation at all. Please do not send others into the woods – Danny '365CSI' Engelman Jun 20 '16 at 08:27
  • Now I need to attach the screen capture for downvoting with this answer to prove that it is downvoted as well as i used it in my project so you will get idea about the same. I know you guys are more knowledgeable than me as sometimes someone downvote me with the valid reason & i thanked those persons in the comments as well. As before my account was hacked (As mentioned by community) & they downvoted my accepted answers as well even though they are correct. Feeling guilty for misguiding someone due to my misunderstanding. Thanks. :) – Hardik Jun 20 '16 at 08:34