The time zone is an artefact of conversion from "instants" to a human-readable date-and-time in some calendar.
Computers do not like human-readable formats (not as much as humans, at least), so they usually store instants in a zone-neutral format. For instance, in the NTFS file system, time stamps are stored in UTC.
Hence, the file time modification is stored properly as long as whoever modifies it knows the current time. If your Windows system displays "13:19" and believes to be in the GMT-5 time zone, then it infers that the current instant is "18:19" in UTC, and writes as much in the NTFS entrails. However, if the OS displays "13:19" but believes to be in the GMT+3 time zone, then the OS is off by eight hours, even if, for the human looking at the screen, things seem fine.
Another point is that the file modification time is a property of the storage system in which the file is stored, e.g. a file system. When a file is "sent", then that time does not necessarily travels with it. Some archive formats (e.g. Zip) embed the file modification time along with the file. This does not apply to a file sent "as is", attached to an email, will not come with a file modification time.
This is for an Excel worksheet. Data is entered or modified in column A. The macro automatically enters the date/time in column B. The macro then sorts column A & B by column B, putting the most recent at the top.
Enter the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
Dim AB As Range
Set A = Range("A:A")
Set AB = Range("A:B")
If Intersect(Target, A) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1) = Now
AB.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
- right-click the tab name near the bottom of the Excel window
- select View Code - this brings up a VBE window
- paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
- bring up the VBE windows as above
- clear the code out
- close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
Best Answer
Windows Vista / 7 and later
Windows Server 2003 and later
With a little effort you can use
forfiles
to get the last modified time of a specific file, seconds included:Example output
The value displayed is based on the local time of the computer and matches the time shown in the file properties dialog.
Usage help
http://technet.microsoft.com/en-us/library/cc753551.aspx
Windows XP
forfiles.exe
is not available out of the box, however you can manually get the required executable. It's an old version which is part of the Windows 2000 Resource Kit. The syntax is case-sensitive and slightly different, and so is the output:Example output
Here the time value is displayed in the UTC format and is not affected by changes in time zone or daylight saving time. In this example the file was last modified at 15:33:54 (UTC).
Note You can obtain the newer
forfiles.exe
version by grabbing a copy of the file from any Windows 2003 Server installation or setup media.