Have you ever forgotten to set the timezone of your digital camera before you went on holiday, and want to fix up the timestamps when you get back? Or maybe you have photos taken on two different cameras, but their clocks were set differently, and you want to reconcile them? This free Windows command-line utility comes to the rescue. It can modify JPEG timestamps, and also rename your images according to their timestamp.
Installation: just save jpegdate.exe somewhere convenient. I save it into my windows directory, so I can run it from the command line.
jpegdate "pic.jpg" /hour +8
for %i in (*.jpg) do jpegdate "%i" /hour +8
for %i in (*.jpg) do jpegdate "%i" /year 2012
for %i in (*.jpg) do jpegdate "%i" /year +12 /month +8 /day +4
/year X /month X /day X /hour X /min X /sec X where X can be a number, or +number or -number for a relative change. Hour is in the range 0-23, using the 24hr clock.
jpegdate "pic.jpg" /rename "%{year}.%{month}.%{day} - %{fn}.jpg"
for %i in (*.jpg) do jpegdate "%i" /rename "%{year}.%{month}.%{day} - %{fn}.jpg"
/rename "%{year}.%{month}.%{day} - %{hour}.%{min} - %{fn}.jpg"
%{year} %{month} %{day} %{hour} %{min} %{sec} %{date} %{time} %{fn} %%
for %i in (*.jpg) do jpegdate "%i" /datefn
The source code is available:
jpegdate is copyright (c) 2012 Lucian Wischik. You may use the source code and executable in any derivative work, in any way you wish. I'd appreciate a mention but it's not necessary. The source code demonstrates how to read the EXIF headers of a JPEG, and how to memory-map a file into memory.
Jpegdate scans through your JPEG file (which is assumed to be in the EXIF file format, seemingly used by all digital cameras nowdays). It looks for all TIFF / IFD and SubIFD directories. Within each directory, it looks for tags 0x132 (DateTime), 0x9003 (DateTimeOriginal), 0x9004 (DateTimeDigitized)
When reading the timestamp of an existing file, it looks at DateTimeOriginal first; failing that, it looks for DateTimeDigitized or DateTime. The EXIF specification says that these fields are always stored inside JPEG file as strings of the form "YYYY.MM.DD HH:MM:SS", in the 24-hour clock.
When writing to the timestamps of an existing file, it writes to whichever of those three tags are present. It never adds additional tags. Therefore, if your JPEG lacks any timestamp, this program will never add one.
When calculating new timestamps, it works up from Seconds through to Years one at a time. For instance: