Adding a suffix to the day?  SOLVED

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
MattyG
Posts: 2
Joined: 19 May 20, 14:20

Adding a suffix to the day?

Post by MattyG » 19 May 20, 14:22

Right now I have a date macro that's -f mmm D, yyyy which creates "May 19, 2020".

However, I'd like to be able to create "May 19th, 2020" or "May 1st, 2020" instead. Is there a way to do that?

Peter Stotz
PhraseExpress Expert
Posts: 850
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 20 May 20, 10:35

@MattyG
I'd like to be able to create "May 19th, 2020" or "May 1st, 2020" instead. Is there a way to do that?
Yes, but it's a little tricky...

Code: Select all

(* 20200520 • Date in a special English date format with ordinal number, e.g. May 2nd, 2020 - May 19th, 2020 and so on
   ##date input ddddd in system standard format
*){#settemp -name ##date -content {#calendar -f ddddd -head Select Date: -manual -locale en-US}}(*
  ##date formatted output
*){#datetime -f mmmm d'{#check -text {#datetime -f d -value {#gettemp ##date}} -case =. 11 -output th|=. 12 -output th|=. 13 -output th|=. 1 -output st|=. 2 -output nd|=. 3 -output rd -else th}', yyyy -value {#gettemp ##date} -locale en-US}
'Locale en-US' was chosen as an example for the regional date format - adapt this for your region if necessary.
Peter
Windows 10 - PhraseExpress v14.0.183

MattyG
Posts: 2
Joined: 19 May 20, 14:20

Post by MattyG » 23 May 20, 02:40

Thanks, this was helpful. Here are my final solutions for today, tomorrow, and yesterday:

Code: Select all

(* Today *)
{#settemp -name ##date -content {-f ddddd -head  Select Date: -manual -locale en-US}{#datetime -s 0D -f mmmm d'{#check -text {#datetime -s 0D -f d -value {#gettemp ##date}} -case =. 11 -output th|=. 12 -output th|=. 13 -output th|=. 1 -output st|=. 2 -output nd|=. 3 -output rd -else th}', yyyy -value {#gettemp ##date} -locale en-US}

(* Just change the two parts that say 0D to get dates relative to today, for example... *)

(* Yesterday *)
{#settemp -name ##date -content {-f ddddd -head  Select Date: -manual -locale en-US}{#datetime -s -1D -f mmmm d'{#check -text {#datetime -s -1D -f d -value {#gettemp ##date}} -case =. 11 -output th|=. 12 -output th|=. 13 -output th|=. 1 -output st|=. 2 -output nd|=. 3 -output rd -else th}', yyyy -value {#gettemp ##date} -locale en-US}

(* Tomorrow *)
{#settemp -name ##date -content {-f ddddd -head  Select Date: -manual -locale en-US}{#datetime -s 1D -f mmmm d'{#check -text {#datetime -s 1D -f d -value {#gettemp ##date}} -case =. 11 -output th|=. 12 -output th|=. 13 -output th|=. 1 -output st|=. 2 -output nd|=. 3 -output rd -else th}', yyyy -value {#gettemp ##date} -locale en-US}

Post Reply