Formatting dates to a specific pattern

Paul Schmehl pschmehl_lists at
Sun Aug 31 02:02:11 UTC 2008

--On August 31, 2008 2:52:07 AM +0300 "Ivan \"Rambius\" Ivanov" 
<rambiusparkisanius at> wrote:

> Hello,
> I need to format the current date (as returned by date(1) ) to the
> pattern m-d-yyyy, where m is the month in one or digits, d is the day
> in one or two digits, and yyyy is the year in four digits. The problem
> for me is the day and the month, for example August should be 8, and
> not 08, and 5th of September should be 9-5-2008 and not 09-05-2008. I
> read the man page of date(1) but date(1) seems to always put leading
> zeros.
> I appreciate any help on how to format the date the way I want.

# date "+%m-%d-%Y" | sed 's/^0//g'

Paul Schmehl, If it isn't already
obvious, my opinions are my own
and not those of my employer.
WARNING: Check the headers before replying

More information about the freebsd-questions mailing list