Best way to sort by date which is part of filename

Hello, would like an bit of advice.
Want to try to get sorting by portion of filename.

Here are name examples:

SomeText.23.05.19.Additional.Text
SomeText.23.04.19.Additional.Text
SomeText.23.03.19.Additional.Text

Text - 2023.05.19 - Additional - Text
Text - 2023.04.19 - Additional - Text
Text - 2023.03.19 - Additional - Text

Found this code, and managed to install it.

While it says that code should detect numbers, and show these in added column, I get "No Number" result.

Tried to adjust regex pattern with GPT help but no luck. What important details I'm missing?

Your digits look more like dates. Which numbers do you want to extract?

I would like to grab these dates.
image
Tried this one, but script with such pattern returns still "No Numbers."

Did you change the underscores to dots?

Sounds like an hint, probably I should...
/^\w+ \d+[.](\d+)/i same bahavior.
Should I restart DO, so changes to JS are applied? Or its enough to remove column and enable it again.

Simply saving the edited script is enough. Maybe a file display refresh.

The regex should probably look more like this (with three capture groups):

var re=/.*(\d+)\.(\d+)\.(\d+).*/;

No luck still.
Initial script, it works for you?
I'm on DO13. Doubt that it breaks certain stuff.

I haven't tried the script :slight_smile:

If you already run v13 use an evaluator column, they are made for this problem and are much easier!

Grabbed these scripts to see if these work.

There are plenty options.
But one I tried - Movie.Year should show an year from metadata, aaaaaand its column is also empty.

Will check evaluator thing. Hear these terms, but was never interested in it. Guess maybe its good time to do.

Try

yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\1");
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\3");

if (yy<100) yy += 2000;

return (yy + "-" + mm + "-" + dd) as date;

Go to

Prefs PAGE="evalcolumns"

and paste this

XML
<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="no" autorefresh="no" foldertype="all" keyword="t47486" maxstars="5" namerefresh="no" reversesort="no" title="t47486" type="0">yy = RegEx(name,&quot;.*?(\d+)\.(\d+)\.(\d+).*&quot;,&quot;\1&quot;);
mm = RegEx(name,&quot;.*?(\d+)\.(\d+)\.(\d+).*&quot;,&quot;\2&quot;);
dd = RegEx(name,&quot;.*?(\d+)\.(\d+)\.(\d+).*&quot;,&quot;\3&quot;);

if (yy&lt;100) yy += 2000;

return (yy + &quot;-&quot; + mm + &quot;-&quot; + dd) as date;</evalcolumn>
1 Like

Yes, this does work.
Thanks a lot, took me a while to find where to even search for these columns.

Just an slight update.
Script refused to show dates for YYYY.MM.DD format.
So far had to edit script to this:
yy = RegEx(name,".*?(\d{2}|\d{4}).(\d+)\.(\d+)\.*","\1");

Now it detects 4digit date, but grabs first two numbers.
Swapping 2 and 4, again makes values to disappear.

image

Try

yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\1");
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\3");

if (yy<100) yy += 2000;

return (yy + "-" + mm + "-" + dd) as date;
2 Likes

Yup, works. Thanks a lot.

This column has benefitted from a bug (automatic type conversion) that was corrected in 13.0.55.

We now need to explicitly convert the string to an integer and change the code accordingly:

yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\1") As int;
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\3");

if (yy<100) yy += 2000;

return (yy + "-" + mm + "-" + dd) As date;
5 Likes