Extract date from filename and apply it as file timestamp

Bulk Rename Utility How-To's

Extract date from filename and apply it as file timestamp

Postby Admin » Sun Jul 13, 2025 12:15 pm

Given a file:
2016-07-14_text-main.jpg
How do I extract the date 2016-07-14 and apply it as file timestamp?

BRU Javascript is needed for that:

Code: Select all
// Example:
//   name = "2016-07-14_text-main.jpg"
// After running this script, newModified  and newCreated will be set to the date 2016-07-14
var match = name.match(/(\d{4}-\d{2}-\d{2})/);
if (match) {
    // split "YYYY-MM-DD" into components
    var parts = match[1].split("-");
    // construct JS Date: months are zero-based
    newModified = new Date(
        parseInt(parts[0], 10),
        parseInt(parts[1], 10) - 1,
        parseInt(parts[2], 10)
    );
    newCreated = newModified;
}


This script will extract the date and apply it as file timestamp modified and created date.

Then, to also apply the date as Exif date in the metadata, use Change File Timestamps option and set Exif Date Taken (Original) / Item Date set to Modified Date
Admin
Site Admin
 
Posts: 2990
Joined: Tue Mar 08, 2005 8:39 pm

Return to How-To