Formatting the date in unix to include suffix on day (st, nd, rd and th)
Posted
by skymook
on Stack Overflow
See other posts from Stack Overflow
or by skymook
Published on 2010-03-22T20:25:48Z
Indexed on
2010/03/22
21:31 UTC
Read the original article
Hit count: 513
How can I add the suffix on the day number of a unix date?
I'll explain. I have a TextMate bundle snippit that writes out today's date. It uses unix date and formatting. Here is the code:
`date +%A` `date +%d` `date +%B` `date +%Y`
It outputs:
Monday 22 March 2010
I would like to add the suffix to the day (st, nd, rd and th) like so:
Monday 22nd March 2010
As far as I can see, there is no native function in the unix date formatting, like there is in PHP (j). How would I achieve this in unix? A complicated regex on the day number?
© Stack Overflow or respective owner