I find your requirement interesting, as it is quite common for a ticketing system.
SharePoint can't do this natively, the reason being that the created and modified dates get written when an item is actually inserted and updated. You need to track the time spent on a form, that is the timespan between the click on the "add new item"/"edit item" button and the click on the "save" button.
The only thing I can see as feasible is resorting to some javascript to keep track of the time spent. So basically a timer function that kicks off as soon as the new form/edit form is opened and on saving, sets a hidden field value with the elapsed time (I would go for the total number of seconds elapsed, it should be easier working with the value later).
This is not that complicated, but some knowledge of both SharePoint and javascript is required.
The complete receipt is as follow:
- add a new column of time Number to your list. Call it eg. timespan
- in SharePoint designer: create a new "new form" and new "edit form" and set them as the default for your list.
- add a script tag to the body of each form, with the following javascript code:
--
<script type="text/javascript">
var startTime = Date.now();
</script>
add a PreSaveAction function that will get called when the save button is clicked:
function PreSaveAction(){
var endTime = Date.now();
var elapsed = (endTime - startTime) / 1000; // total number of seconds
var timespanFieldValue = $('[title="timespan"]').val(); //current timespan (this should have some value if in edit form)
var currentTimespan = isNaN(parseInt(timespanFieldValue )) ? 0 : parseInt(timespanFieldValue);
$('[title="timespan"]').val(currentTimespan + elapsed);
}
(The last javascript snippet requires jQuery).