Date Format with Ordinal Indicators?

Discussion, questions and support.
Post Reply
GapsOfTheGod
Posts: 10
Joined: Feb 22nd, ’21, 08:05

Post by GapsOfTheGod » Feb 24th, ’21, 12:22

Hi all, I want to format a date as follows: Wednesday, 24th February 2021.

How would I go about including the ordinal indicators (st, nd, rd, th)?

Thanks!
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Feb 24th, ’21, 19:13

Nice challenge! There is no standard format for this in Windows so you need to use a small script.
Use "Insert Command Code" macro to insert the following code:

Code: Select all

Send, % A_DDDD ", " Ordinal(A_DD) " " A_MMMM " " A_YYYY
return

Ordinal(D){
   Static Special := {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"}
   Return D . ((S := Special[D]) ? S : "th")
}
https://www.autohotkey.com/boards/viewtopic.php?t=59936
GapsOfTheGod
Posts: 10
Joined: Feb 22nd, ’21, 08:05

Post by GapsOfTheGod » Feb 25th, ’21, 07:56

Thanks Tom, I do like to be challenging :lol:

I'll give that a shot.

Thank you again.
GapsOfTheGod
Posts: 10
Joined: Feb 22nd, ’21, 08:05

Post by GapsOfTheGod » Feb 25th, ’21, 08:16

Please could you point me in the direction of where I can work out how to combine this ordinal formatting with the dateshift feature? Basically, within the body of a text expansion, I want to show today+7, formatted with that ordinal format you've kindly given to me above.
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Feb 26th, ’21, 09:40

Try this:

Code: Select all

date:=A_Now
date += 4, days
day:=SubStr(date, 7, 2)
Special := {1: "st", 2: "nd", 03: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"}
S := Special[day] ? Special[day] : "th"
FormatTime, date, %date%, dddd, d'%S%', MMMM yyyy
send, % date
GapsOfTheGod
Posts: 10
Joined: Feb 22nd, ’21, 08:05

Post by GapsOfTheGod » Feb 26th, ’21, 15:08

Thanks Tom, that's getting me the following:

---------------------------
FastKeys.exe
---------------------------
Error at line 153.

Line Text: <html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Debt C...
Error: Invalid `%.

The program will exit.
---------------------------
OK
---------------------------

It's a HTML formatted text expansion, however when I remove the %CODE_TdyPlus7% variable (containing the code you provided above), I get no errors (and of course no value!).

Any ideas?
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Feb 27th, ’21, 14:35

Sorry, Insert command code macro only works in Non formatted text mode.
Post Reply