how to change the dates based on the file name

Bulk Rename Utility How-To's

how to change the dates based on the file name

Postby Sams » Sat Sep 06, 2025 12:05 am

Hi I'm a new user and need some help.

I have a folder of photos with incorrect date metadata, but each filename contains the correct date and time. I'd like to automatically update the metadata using that information.

For example:

20220917130620_IMG_2167

Set Date as: 17-09-2022 13:06h

Is this possible?
Sams
 
Posts: 2
Joined: Fri Sep 05, 2025 11:50 pm

Re: how to change the dates based on the file name

Postby Admin » Sat Sep 06, 2025 1:59 am

Yes — this is possible with Bulk Rename Utility. You can parse the date/time out of each filename and set the file timestamps (Created/Modified/Accessed) to that value; you can also (optionally) propagate those timestamps into the file's EXIF "Date Taken" where supported.

Recommended approach (safe, test on a copy first)
1. Make a backup or work on a copy of a few files to test.
2. Preview first - the file list New Name column and a small test run are your friend.

Two ways: quick manual (limited), or reliable per-file automatic (recommended)

A. Quick/manual (if all files share the same single date)
- Special -> Change File Timestamps lets you set a fixed Created/Modified/Accessed date (or Current) or apply a Delta. Not suitable when each file needs a different timestamp extracted from its filename.

B. Automatic/per-file (recommended) — use JavaScript renaming
- Use the integrated JavaScript engine (Special (14) -> Javascript) to:
- Parse the timestamp from the filename (your example shows leading YYYYMMDDhhmmss_).
- Build a JavaScript Date from the components.
- Assign that Date to newCreated and/or newModified (these are provided variables — BRU will apply those timestamps).
- Leave the filename unchanged (or change it if you want).

Sample JavaScript to paste into Special -> Javascript (adjust if your filename pattern differs):

// filenames like: 20220917130620_IMG_2167
// name is the file name without extension (BRU variable)
var m = name.match(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/);
if (m) {
// m[1]=YYYY, m[2]=MM, m[3]=DD, m[4]=hh, m[5]=mm, m[6]=ss
var dt = new Date(
parseInt(m[1],10),
parseInt(m[2],10) - 1, // JS months 0..11
parseInt(m[3],10),
parseInt(m[4],10),
parseInt(m[5],10),
parseInt(m[6],10)
);
// Set both Created and Modified to this date/time
newCreated = dt;
newModified = dt;
// keep filename unchanged
newName = name;
} else {
// no match: leave unchanged (or handle error)
newName = name;
}

Notes and options
- Timezones: JavaScript Date uses local timezone. If your timestamps are in UTC or another zone, adjust accordingly (e.g., use Date.UTC(...) then newCreated = new Date( Date.UTC(...)) or add/subtract offset).
- EXIF "Date Taken": Bulk Rename Utility can write EXIF Date Taken from the file Created or Modified timestamps. After the timestamps are changed, enable the option in the Special menu that says something like "Exif Date Taken (Original) / Item Date set to change the value of the Exif Date Taken to the file Created Timestamp or Modified Timestamp" so the EXIF tag is updated. (EXIF writing is only available for supported image formats.)
- Supported image EXIF write/read: JPG/JPEG/TIFF/NEF/CR2 and the other formats listed in the EXIF docs. If a file type does not support EXIF, that step will do nothing for that file type.
- Test on a few files first, use Preview, and only run on the full set when you’re happy.
- If you want to remove the leading date from the filename after using it to set timestamps, you can set newName accordingly in the script (e.g., newName = name.replace(/^\d{14}_?/, '')).
Admin
Site Admin
 
Posts: 3064
Joined: Tue Mar 08, 2005 8:39 pm

Re: how to change the dates based on the file name

Postby Sams » Sat Sep 13, 2025 12:42 pm

Hi,

Thanks for your reply.

Is there any other way to do this automatically without using JavaScript?

Just because I'll only use this time to organize my photos in onedrive.
Sams
 
Posts: 2
Joined: Fri Sep 05, 2025 11:50 pm


Return to How-To


cron