ExifTool Forum

ExifTool => Newbies => Topic started by: bayu on October 03, 2020, 08:33:07 AM

Title: Get format date from filename "somestring-ddmmYYYY{random number}.jpg
Post by: bayu on October 03, 2020, 08:33:07 AM
HI everyone,

I do insert date from  filename that strapdown send by whatsapp without any problem.

filename :  IMG-20190512-WA0015.jpg

exiftool "-datetimeoriginal<${filename;$_=substr($_,3,9)} 00:00" IMG-*wa*.jpg   

at the same time i also have filename like this:
filename: IMG-12052020-WA0015.jpg

could anyone help me to convert/format from "ddmmYYYY" into "YYYYmmdd".
any help appreciate.

Thank you
Bayu
Title: Re: Get format date from filename "somestring-ddmmYYYY{random number}.jpg
Post by: Phil Harvey on October 03, 2020, 08:59:28 AM
Hi Bayu,

Try this:

exiftool "-datetimeoriginal<${filename;$_=substr($_,4,8);s/(\d{2})(\d{2})(\d{2})/$3:$2:$1/} 00:00" IMG-*wa*.jpg

To see what the expression is doing, you can use the -p option:

exiftool -p "${filename;$_=substr($_,4,8);s/(\d{2})(\d{2})(\d{2})/$3:$2:$1/} 00:00" IMG-*wa*.jpg

- Phil
Title: Re: Get format date from filename "somestring-ddmmYYYY{random number}.jpg
Post by: greybeard on October 03, 2020, 09:02:19 AM
Another alternative

exiftool "-datetimeoriginal<${filename;$_=substr($_,8,4).substr($_,6,2).substr($_,4,2)} 00:00" IMG-12052020-WA0015.jpg
Title: Re: Get format date from filename "somestring-ddmmYYYY{random number}.jpg
Post by: bayu on October 03, 2020, 09:15:36 AM
Hi Phil,

thank you for your quick replay. i can say your tool was amazing.

exiftool -p "${filename;$_=substr($_,4,8);s/(\d{2})(\d{2})(\d{2})/$3:$2:$1/} 00:00" IMG-*wa*.jpg

will be output : 20:05:1220 00:00


so i do make adjustment  become:

exiftool -p "${filename;$_=substr($_,4,8);s/(\d{2})(\d{2})(\d{2})/$1:$2:$3/} 00:00" IMG-*wa*.jpg

and the output :  12:05:2020 00:00

as expected, i hope this will also help anyone else with same problem.

note:
am using command from windows 10 64bit if it make any different.
my filename: IMG-12052020-WA0015.jpg

Thank you Phil,
Title: Re: Get format date from filename "somestring-ddmmYYYY{random number}.jpg
Post by: bayu on October 03, 2020, 09:19:55 AM
Hi greybeard,

thank you for your replay, you are correct, your output is -datetimeoriginal<20200512 00:00 as expected.

another alternative for same problem.

Thank you and i hope it will help anyone else also.

Bayu
Title: Re: Get format date from filename "somestring-ddmmYYYY{random number}.jpg
Post by: Phil Harvey on October 03, 2020, 09:27:25 AM
Quote from: bayu on October 03, 2020, 09:15:36 AM
exiftool -p "${filename;$_=substr($_,4,8);s/(\d{2})(\d{2})(\d{2})/$3:$2:$1/} 00:00" IMG-*wa*.jpg

will be output : 20:05:1220 00:00

Opps.  You're right.  I meant s/(\d{2})(\d{2})(\d{4})/$3:$2:$1/

- Phil