Get format date from filename "somestring-ddmmYYYY{random number}.jpg

Started by bayu, October 03, 2020, 08:33:07 AM

Previous topic - Next topic

bayu

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

greybeard

Another alternative

exiftool "-datetimeoriginal<${filename;$_=substr($_,8,4).substr($_,6,2).substr($_,4,2)} 00:00" IMG-12052020-WA0015.jpg

bayu

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,

bayu

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

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).