I would like to make a column that shows how old a list item is. Since the calculated value [Today] isn't supported I need to come up with another way to subtract date created with the current date.
To reiterate I need a column that always shows the current date as days go on.
I figured I would make a script that would always give the current day:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
document.write(today);
//document.querySelector(".class").innerHTML = (today);
//document.getElementById("id").innerHTML = (today);
Now I figured it sure would be easy to just use the .innerHTML
with a corresponding id but I only have classes to work with. Again the class structure isn't specific enough to just insert my today's date into its cell.
So I'm really stuck guys and my SharePoint developing experience is hitting a wall.
Idea:
So I've used SP services in the past and thought that maybe it's UpdateListItems
operation might help. Primarily this example:
$(document).ready(function() {
$("#feedback-submit input").click(function() {
var subject = $("#feedback-subject-input input").val();
var message = $("#feedback-message-input textarea").text();
CreateNewItem(subject, message);
});
});
function CreateNewItem(subject, message) {
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: "Feedback",
valuepairs: [["Title", subject], ["Message", message]],
completefunc: function(xData, Status) {
alert("completed");
}
});
}
I was thinking if this was able to create a list item it could be able to add my current date javascript to it when the item is created. But again my ability to manipulate code this advanced is out of my ability.
Again any help would be appreciated.
Code Review:
Alright so I took a shot at creating a mock up of what I think might work. I haven't tested it because I am unsure if this is even legal in regards to syntax and structure.
$(document).ready(function() {
$("no_idea_what_to_put_here").click(function() {
var date = $("no_idea_what_to_put_here").val();
CreateNewItem(date);
});
$(document).ready(function CreateNewItem(date) {
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: "LISTNAME",
valuepairs: [document.write(today), date],
completefunc: function(xData, Status) {
alert("completed");
}
});
});
$(document).ready(function() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
});
});