# Rule for Date Change

**URL:** <https://discourse.devontechnologies.com/t/rule-for-date-change/86933>\
**Category:** Tips\
**Tags:** automation\
**Created:** [May 17, 2026, 8:05pm UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933 "2026-05-17T20:05:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoSel](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/e19b73/32.png) [@MoSel](https://discourse.devontechnologies.com/u/MoSel)\
**Post date:** [May 17, 2026, 8:05pm UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/1 "2026-05-17T20:05:59Z")

</div>

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!

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/d/b/dba9fbdbd10a4ac924760b3c1691a4617bc0c3ad.jpeg)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [May 17, 2026, 10:38pm UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/2 "2026-05-17T22:38:00Z")

</div>

- 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?

---

<div class="post-metadata">

**Author:** ![DTLow](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/dtlow/32/18161_2.png) [@DTLow](https://discourse.devontechnologies.com/u/DTLow)\
**Post date:** [May 18, 2026, 3:20am UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/3 "2026-05-18T03:20:43Z")

</div>

> [@MoSel](#):
>
> changes the Document Date to the Date in the file name “YYMMDD\_FileName”

This can be done using an AppleScript

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [May 18, 2026, 4:44am UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/4 "2026-05-18T04:44:39Z")

</div>

> [@MoSel](#):
>
> I cannot figure out, how to use the function “Datum ändern” to use a variable from an action before for example like “Name scannen”

After using _Scan Name/Text \> Date_, the _Document Date_ placeholder can be used in this case.

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 18, 2026, 10:26am UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/5 "2026-05-18T10:26:46Z")

</div>

> [@cgrunenberg](#):
>
> After using _Scan Name/Text \> Date_, the _Document Date_ placeholder can be used

Doesn’t work for me.

 ![Bildschirmfoto 2026-05-18 at 12.19.48](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/3/0/304518e1964fec0a35fe0eb2d22770e1ab88be4b.jpeg)

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

 ![Bildschirmfoto 2026-05-18 at 12.22.15](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/3/2/32e2b80e53e940c643dff8f0f41c91fe4f6363d5.png)

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

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 18, 2026, 11:17am UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/6 "2026-05-18T11:17:08Z")

</div>

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.

```javascript
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;
    }
  })
}

```

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [May 18, 2026, 1:00pm UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/7 "2026-05-18T13:00:46Z")

</div>

> [@chrillek](#):
>
> 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.

Dates without any separators at all aren’t supported.

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [May 18, 2026, 1:09pm UTC](https://discourse.devontechnologies.com/t/rule-for-date-change/86933/8 "2026-05-18T13:09:58Z")

</div>

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