Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Ok I must be missing something. I have a section with the "last updated date" in a text cell, I'd like it to autoupdate. Is there a "insert current date" command hidden away in some menu?

Edit

How can I automatically insert the current date and time into a notebook each time I save it to indicate the date and time last modified?

share|improve this question

3 Answers 3

If you want this done automatically then the way I would do it is to time stamp the notebook as you close it, i.e. the time stamp appears after "Last modified".

This code might be overkill but it will do the job:

Create a text cell with "Last Modified " in it and give it a cell tag (in this example "LastModified"), then ...

SetOptions[EvaluationNotebook[], 
 NotebookEventActions :> {"WindowClose" :> 
    Module[{dy, hr, mn}, {dy, hr, mn} = 
      Map[(LinkWrite[First[$FrontEnd], FrontEnd`Value[#]]; 
             LinkRead[First[$FrontEnd]]) &, {"DateLong", "Hour", 
        "Minute"}]; NotebookLocate["LastModified"]; 
     NotebookWrite[InputNotebook[], 
      Cell[TextData[{"last modified ", dy, " at ", hr, ":", mn}], 
       "Text", CellTags -> "LastModified"]]]}
 ]
share|improve this answer
    
Mike, I was about to delete this question in routine clean-up. If you care to edit the question in a bid for reopening do so now, please. –  Mr.Wizard Jun 26 at 18:37
    
@Mr.Wizard lucky I saw this. Have not been on here very much in recent weeks. I wasn't quite sue what you meant but have modified the question –  Mike Honeychurch Jun 26 at 23:26
    
I am glad you could reply. I hope that whatever is occupying your time is either enjoyable or profitable for you. :-) Your edit seems good enough to me so I reopened the question. Thanks. –  Mr.Wizard Jun 27 at 3:19

If you want to see when the notebook was last changed you could also use the information that is collected by the "Notebook History" functionality (of course only when you did not disable that functionality in the Advanced tab of the preferences). The following creates a cell which automatically keeps track of any change times, whether or not they have been saved to file:

  Row[{"Last Change: ", Dynamic[
     DateString@Max@Flatten[
     Cases[NotebookGet[], Verbatim[Rule][CellChangeTimes, v_] :> v, 
     Infinity]
  ], UpdateInterval -> 10]}]

you could of course use similar code to update a cell only when the notebook is closed like Mike has shown or use an explicit update button to do the update. Another alternative would be to creat your own palette/docked cell with a save button which would determine the newest CellChangeTimes value of the given notebook, write it to the notebook and save after that. Unfortunately there is no hook to do this on "NotebookSave" (as for "WindowClose") AFAIK...

share|improve this answer

If you want the message to show when you last run that command, all you have to do is add this to the cell you're evaluating:

message = DateString[DateList[]]  ;
Print["This was last updated on  " <> message]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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