Rule for Date Change

Hi,

I want to have a rule, which changes the Document Date to the Date in the file name “YYMMDD_FileName”. I cannot figure out, how to use the function “Datum ändern” to use a variable from an action before for example like “Name scannen” or a “Chat Anfrage” - in the drop down I cannot choose anything but the standards. Can anyone help? Thanks!

  • Why haven’t you defined any criteria in this smart rule?
  • You haven’t provided any concrete example of a filename containing a date you’d be processing so it’s impossible to assist specifically.

PS: There are many similar questions on these forums. Have you done a search before posting this?

This can be done using an AppleScript

1 Like

After using Scan Name/Text > Date, the Document Date placeholder can be used in this case.

Doesn’t work for me.

I have a file with the date YYMMDD_ at the start of the filename according to the OP’s description (in the screenshot, an unrelated file is highlighted, though. I ran the smartrule on the one just above). And a smartrule

which I assume (!) is doing what you said. However, the long document date is 2022-06-18, not 2025-01-23, as desired.

Perhaps my smart rule is doing the wrong thing?

This is with DT 4.2.2 on macOS 15.7.3

Here’s a script for a smart rule that does what you want. It’s written in JavaScript and obviously overcommented – but still created by Human Intelligence 1.0
Use it in an “Execute JavaScript” action in your smart rule, and make sure to select documents in the smart rule, too.

The code assumes that all dates are in the 21st century, i.e. “YY” at the beginning of the name is converted to “20YY” for the document date. If you have documents whose name reflects a date in the 20th century, you must adapt the code for that.

function performsmartrule(records) {

  /* Loop over all records selected by the smart rule condition(s) */
  records.forEach(r => {

	/* Get the current record's name */
    const name = r.name();

    /* Check if the name begins with six digits followed by an underscore */
    const matchDate = name.match(/^(\d{6})_/);
    if (matchDate)  {
	  /* For matching record: 
         convert the six digits to a date string in ISO format */
      const rawDate = matchDate[1].replace(/(\d\d)(\d\d)(\d\d)/,"20$1-$2-$3");

	  /* Create a date object from the date string */
      const date = new Date(rawDate);

	  /* Set the current record's date to the date from the name */
      r.date = date;
    }
  })
}
1 Like

Dates without any separators at all aren’t supported.

1 Like

Which makes sense – 250123 could be 23 January 2025 as well as 25 January 2023.