I want to create list column that will show current time of an item. Not time when item was edited or created but current time and it should show time anytime (always).
Asked
Active
Viewed 247 times
0
-
1How can an item have a current time? I haven't started drinking today, but probably I need a couple of pints to understand this :) – Paul Strupeikis Sep 23 '15 at 09:51
-
current time of computer or server. so current time to put in a list column in every item of that list. I maybe didn't make myself clear. Pardon me. – Danilo Sep 23 '15 at 09:54
-
Sorry for the joke. On topic: you won't be able to do that as column values are saved when item is saved. As far as I know - there is no way how to do that, except for a custom field maybe. Another question, WHY would you do that kind of thing? users can see current time one the lower right hand side corner of the screen :) – Paul Strupeikis Sep 23 '15 at 09:57
-
I need it for some other calculations. – Danilo Sep 23 '15 at 09:58
-
To set value to another auto-calculated column? So just use [Now] in the formula of that column. This seems like an "XY problem" to me. – Paul Strupeikis Sep 23 '15 at 10:02
-
nope. i need to do calculation example current time-some other time from another column. [now] is not working I tried that at first. I know one or maybe two solutions but are not acceptable for my colleagues. First one is to create workflow that will update item and change nothing, just edit so I can get current time and put it in the mentioned column. second option is to put list in WP page, use javascript to get current time of computer. – Danilo Sep 23 '15 at 10:03
1 Answers
3
You can use a calculated column for this. Set the return type to return as number.
Create a calculated column and add this formula:
="<img src='/_layouts/images/blank.gif' onload=""{"
&" var day=new Date();"
&" var n = day.getTime();"
&" this.parentNode.innerHTML= n;"
&"}"">"
But this will give you milliseconds. You can get the hours / minutes / seconds with :
day.getHours();
day.getMinutes();
day.getSeconds();
You can also use day.toTimeString().split(" ")[0]; to get the time string.
This will just be for display. You won't be able to use this for calculations though. I'll suggest doing the calculations in the calculated column itself.
Credits to Danny Engelman for all his work on calculated columns.
Akhoy
- 2,911
- 2
- 18
- 28
-
For me it's only showing
<img src='/_layouts/images/blank.gif' onload="{ var day=new Date(); var n = day.getTime(); this.parentNode.innerHTML= n;}">in the column..? – wheeler Sep 23 '15 at 10:29 -
1
-
How you mean do calculations in calculated column itself? Do you mean to make substraction (pr any other math. operation) in that column where I got miliseconds? – Danilo Sep 23 '15 at 10:50
-
1
-
-
-
tnx, Akhoy, Please refer all Today questions to the SO answer with all the details: http://sharepoint.stackexchange.com/questions/151144/how-to-use-today-and-me-in-calculated-column/151336#151336 – Danny '365CSI' Engelman Sep 24 '15 at 13:13