# Smart Rule date format recognition

**URL:** <https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581>\
**Category:** DEVONthink\
**Created:** [July 31, 2020, 3:07pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581 "2020-07-31T15:07:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmc](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/w/58f4c7/32.png) [@wmc](https://discourse.devontechnologies.com/u/wmc)\
**Post date:** [July 31, 2020, 3:07pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/1 "2020-07-31T15:07:14Z")

</div>

I have a number of documents with multiple dates, all in the format 09Jul20. Conversion to text shows no OCR errors. Dates are not recognized in smart rules.  
Is this format not supported by the “document date” and old/new variations?

---

<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:** [July 31, 2020, 3:15pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/2 "2020-07-31T15:15:31Z")

</div>

Correct. That wouldn’t be a valid date.

Is this a format of your choosing, or do you have any control over it?

---

<div class="post-metadata">

**Author:** ![wmc](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/w/58f4c7/32.png) [@wmc](https://discourse.devontechnologies.com/u/wmc)\
**Post date:** [July 31, 2020, 3:28pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/3 "2020-07-31T15:28:07Z")

</div>

No control. Used by my Honda dealer’s service software for service tickets/invoices. No idea how common the software is.

Been using Hazel for this, just trying to move as much as I can within DT3.

---

<div class="post-metadata">

**Author:** ![mmynsted](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/mmynsted/32/9470_2.png) [@mmynsted](https://discourse.devontechnologies.com/u/mmynsted)\
**Post date:** [July 31, 2020, 4:06pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/4 "2020-07-31T16:06:40Z")

</div>

You should be able to alter the date with either Hazel or DT. If it were me I would do this in Hazel before sending it to DT.

I have not done this but I do not think the AppleScript would be too bad.

[https://developer.apple.com/documentation/foundation/nsdateformatter?language=occ](https://developer.apple.com/documentation/foundation/nsdateformatter?language=occ)

> **[Custom date time format](https://forum.latenightsw.com/t/custom-date-time-format/2041)**
>
> Hello I often use this handler to date\_time stamp files. #===== on horoDateur() set theFormatter to current application's NSDateFormatter's new() theFormatter's setDateFormat:"yyyy-MM-dd hh:mm:ss" return (theFormatter's...

I am not sure what that data format string is from the Honda dealer.  
Maybe `ddmmmyy`?

---

<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:** [July 31, 2020, 4:20pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/5 "2020-07-31T16:20:55Z")

</div>

Start a support ticket and send me an example document and what date you expect to glean from it. Thanks!

---

<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:** [July 31, 2020, 4:26pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/6 "2020-07-31T16:26:24Z")

</div>

> [@mmynsted](#):
>
> I am not sure what that data format string is from the Honda dealer.  
> Maybe `ddmmmyy` ?

Kinda. But they use an abbreviated month string. Weird. But anyway, one could get at it from within DT3 with a regular expression like

```auto
(\d{2})(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\d{2})

```

and then get at the parts of the date with \1 for the day, \2 for the month and \3 for the year. This should be possible in a smart rule, so no scripting required.

However, if one wants a numeric month, there’d be no way around scripting (afaik). And in this case, I’d rather go with JavaScript then AppleScript because of the support for regular expressions in the former. The regular expression remains the same as above, but one needs some code to get at the capturing parenthesis, e.g.

```auto
let matches = rec.plainText.match(/(\d{2})(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\d{2})/);
let day = matches[1];
let month = matches[2]; /* see below for numerical months */
let year = matches[3]; /* possibly add 2000 to it */

```

One could use a simple array containing the month names and then use  
`monthNames.index(month) + 1` to get the numeric value. If leading zeroes are required, use

```auto
 ('0'+(monthNames.index(month) + 1)).slice(-2) 

```

Off the top of my hat, not tested at all.

---

<div class="post-metadata">

**Author:** ![anon6914418](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@anon6914418](https://discourse.devontechnologies.com/u/anon6914418)\
**Post date:** [July 31, 2020, 4:48pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/7 "2020-07-31T16:48:06Z")

</div>

Or create 12 rules, one for each month, no script required.

I would walk through all invoices and check the abbreviated months and use those in the regex. @chrillek’s guess is probably right though.

Edit: and while I’m at it, IMHO there’s only one proper date format and that is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) (reverse date YYYYMMDD).

---

<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:** [July 31, 2020, 4:58pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/8 "2020-07-31T16:58:51Z")

</div>

> Edit: and while I’m at it, IMHO there’s only one proper date format and that is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) (reverse date YYYYMMDD).

🤔  
I think you meant: MMDDYYYY 😉 😛

---

<div class="post-metadata">

**Author:** ![Greg\_Jones](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/greg_jones/32/7251_2.png) [@Greg\_Jones](https://discourse.devontechnologies.com/u/Greg_Jones)\
**Post date:** [July 31, 2020, 5:05pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/9 "2020-07-31T17:05:03Z")

</div>

> [@BLUEFROG](#):
>
> I think you meant: MMDDYYYY

Try sorting a list of documents by name that have your format as the name prefix and tell us how that works out for you!

---

<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:** [July 31, 2020, 5:22pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/10 "2020-07-31T17:22:44Z")

</div>

I actually do use that format _(which is generally considered an “American format”)_ and it sorts just fine **for me** since I’m only sorting on the month in this instance.

Ex. `SomeCompany_PAID_07312020`

I also do a year end cleaning and put the files into a year group.

---

<div class="post-metadata">

**Author:** ![wmc](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/w/58f4c7/32.png) [@wmc](https://discourse.devontechnologies.com/u/wmc)\
**Post date:** [July 31, 2020, 5:26pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/11 "2020-07-31T17:26:44Z")

</div>

All: thanks for the comments. Didn’t think a simple question like this would get so much attention.

> [@mmynsted](#):
>
> You should be able to alter the date with either Hazel or DT. If it were me I would do this in Hazel before sending it to DT.

Been doing it in Hazel, DT won’t detect it. Not gonna get into regex and/or scripting since I can continue to use my Hazel rules.

> [@chrillek](#):
>
> Kinda. But they use an abbreviated month string. Weird. But anyway, one could get at it from within DT3 with a regular expression like

see my comment above, Hazel works, was trying to do it in DT3 only if I could use the built-in date functions. With regex and/or script still need to find the specific date, change the format, etc.

> [@BLUEFROG](#):
>
> Start a support ticket and send me an example document and what date you expect to glean from it.

Appreciate the help as always, Jim, but while I can delve into regex as a learning experience (and may), my question was just to confirm my suspicion that the format is not supported by DT3’s smart rule. Hazel works and I’m happy to keep that workflow unless DT3 supports the format in the future.  
If you still want the doc to play with, let me know.

* * *

ALL: TLDR: Sticking with Hazel at least for now.

---

<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:** [July 31, 2020, 5:27pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/12 "2020-07-31T17:27:56Z")

</div>

Indeed, I’d still like to check it out. It’s always good to have external input to see if there’s something we can do better. Thanks!

---

<div class="post-metadata">

**Author:** ![wmc](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/w/58f4c7/32.png) [@wmc](https://discourse.devontechnologies.com/u/wmc)\
**Post date:** [July 31, 2020, 5:36pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/13 "2020-07-31T17:36:38Z")

</div>

Ticket #854248 submitted. Thanks!

---

<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:** [July 31, 2020, 5:43pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/14 "2020-07-31T17:43:28Z")

</div>

Appreciated! 🙂

---

<div class="post-metadata">

**Author:** ![anon6914418](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@anon6914418](https://discourse.devontechnologies.com/u/anon6914418)\
**Post date:** [July 31, 2020, 6:22pm UTC](https://discourse.devontechnologies.com/t/smart-rule-date-format-recognition/57581/15 "2020-07-31T18:22:47Z")

</div>

> [@BLUEFROG](#):
>
> I think you meant: MMDDYYYY

The times I’ve accidentally used that format, was when I hadn’t performed [ISO 3103](https://en.wikipedia.org/wiki/ISO_3103) yet 🙂
