0

I'm trying to use the date bash command to get a string like this:

(May 30th, 2022)

I'm getting close with date +"(%B %-d, %Y)", which prints string like that:

(May 30, 2022)

However, the th suffix is missing.

Which format string should I use with date to get the st, nd or th suffix, please?

Thanks in advance!

fgalan
  • 11,732
  • 9
  • 46
  • 89
  • 1
    See https://stackoverflow.com/questions/2495459/formatting-the-date-in-unix-to-include-suffix-on-day-st-nd-rd-and-th – fpmurphy May 30 '22 at 09:35

1 Answers1

1

Try

date +"(%B %-d, %Y)" | sed 's/1,/1st,/;s/2,/2nd,/;s/3,/3rd,/;s/\([0-9]\),/\1th,/'
  • You can easily combine these `sed` scripts into one; see https://stackoverflow.com/questions/7657647/combining-two-sed-commands – tripleee May 30 '22 at 10:10