Help with js script

I have a picture folder that holds a lot of photos from work and school, and I would like to group and sort the photos by adding a new column
Add a new column named "dategroup", the requirement is to compare the creation date, access date, modification date, shooting date (may have, may be empty) in the earliest date as the value of "dategroup", the format is "yyyy year mm month dd day".
I don't know how to write js scripts, I tried to use gpt to help me write, but the result is not good, always reporting errors.
I don't know what to do!