# Is there a way to obtain the time when an input was executed in a notebook?

I have a notebook with lots of In[n] in my current session. The notebook has been open for over three days. I would like to get the timestamps for when certain old inputs--say In[50] and In[100]--were executed.

Is there any way to extract such metainformation from a notebook?

• Cell > Notebook History perhaps? – AccidentalFourierTransform May 31 '18 at 17:53
• Try Map[Options[#, CellChangeTimes] &, Cells[EvaluationNotebook[]]] If Notebook history was turned on. Also if history is on you can also go to a cell and Ctrl+Shift+E to reveal a full form like of the cell and Ctrl+Shift+E again to return to standard display – Hans May 31 '18 at 17:57
• Strongly related: "How do I get the timing of an evaluation after it has already finished?" – Alexey Popkov Oct 16 '19 at 13:29

Update

It turns out that there is a much simpler method than my previous answer. If you need the actual cell label value, than I think messing around with the CellLabelAutoDelete option is necessary. On the other hand, if you know what the CellLabel is, then Cells is perfectly capable of returning the corresponding Cell. So, the following is a simpler version:

cellTimes[n_Integer?Positive] := gmtAbsoluteTimeToString @ Max @ CurrentValue[
Cells[CellLabel -> "In["<>ToString[n]<>"]:="],
CellChangeTimes
]

gmtAbsoluteTimeToString[time_] := DateString @ TimeZoneConvert[
DateObject[time,TimeZone->0]
]


You can make use of the Cells function to do this, although it's a bit difficult to extract the CellLabel. With the default CellLabelAutoDelete -> True, Cells will not return the CellLabel of a cell. The following function changes the option setting for CellLabelAutoDelete, and then looks for the time stamp of the given input cell:

cellTimes[n_Integer?Positive] := With[{cells = Cells[CellStyle->"Input"]},
InternalWithLocalSettings[
CurrentValue[EvaluationNotebook[], CellLabelAutoDelete] = False,
gmtAbsoluteTimeToString @ Max @ CurrentValue[
Pick[
cells,
CurrentValue[cells, CellLabel],
"In["<>ToString[n]<>"]:="
],
CellChangeTimes
],
CurrentValue[EvaluationNotebook[], CellLabelAutoDelete] = Inherited
]
]

gmtAbsoluteTimeToString[time_] := DateString @ TimeZoneConvert[
DateObject[time,TimeZone->0]
]


For example:

DateString[]


"Thu 31 May 2018 11:13:46"

Pause[10]
cellTimes[\$Line - 2]


"Thu 31 May 2018 11:13:46"

• @anderstood Yes, I forgot to correct for a time zone issue. – Carl Woll May 31 '18 at 18:15
• Strictly speaking, CellChangeTimes` contains times when the cell was edited, not when it was evaluated, unfortunately. So this method will give approximate execution times only under assumption that the cell was edited right before evaluation. – Alexey Popkov Oct 16 '19 at 13:23