Change original time in images

Advanced Renamer forum
#1 : 23/11-18 13:06
Mikel
Mikel
Posts: 2
Hi,

I'm changing the filenames of some images using the "Add" method and the next pattern:

<Img Month>-<Img Day>_<Img Hour><Img Min>_

Example:

Original filename: DSC_0137
New filename: 10-27_0239_DSC_0137

The problem is that when I took the photos I didn't change the hour in the camera (I was on holiday in a foreign country), so the hour that appears in the new filename is not right.

The question is... Is it possible to change automatically the hour adding to it the difference between my local time at home and the local time where I took the photos?

I was thinking about something like this:

<Img Month>-<Img Day>_10+<Img Hour><Img Min>_

Desired filename: 10-27_1239_DSC_0137

But it doesn't work...

Thanks in advance!



23/11-18 13:06
#2 : 26/11-18 13:16
David Lee
David Lee
Posts: 59
Reply to #1:
You will need to use a script to achieve this.

Simply adding 10 to the number of hours is not sufficient since the addition could take you into the next day or the next month or even year.

Simplest solution is first to convert the date to a UNIX timestamp (ie milliseconds since 00:00:00 on 1st January 1970), add 10 hours (ie 10×3,600,000ms) and then convert back to a date string. Finally extract and format the elements you want.

Try the following script:

date = Date.parse(item.imgDate)+10*3600000;
date$ = new Date(date);
return ("0" + (date$.getMonth() + 1)).slice(-2)
+ "-" + ("0" + date$.getDate()).slice(-2)
+ "_" + ("0" + date$.getHours()).slice(-2)
+ ("0" + date$.getMinutes()).slice(-2)
+ "_" + item.name;

Note that you must add 1 to the month since UNIX numbers months from Jan = zero. The other fiddling in the return statement adjusts the output to add leading zeroes, where required, to each element.

If you want a better idea of how it works try entering simply date and then date$ in the return statement.


26/11-18 13:16 - edited 26/11-18 13:17
#3 : 29/11-18 13:56
Mikel
Mikel
Posts: 2
Reply to #2:

Thank you so much!

It has worked perfectly!


29/11-18 13:56