Formatting dates to a specific pattern

Ivan "Rambius" Ivanov rambiusparkisanius at gmail.com
Sun Aug 31 00:12:16 UTC 2008


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.

In case you wonder why I need such a format: I am using a hosting
company to run a web site. They are backing up my files in a .tar.gz
archive and I can download it. The name of the backup archive contains
the date formatted as I explained. I want to write a daily cron job
script that will download the backup for me.

Regards
Rambius

-- 
Tangra Mega Rock: http://www.radiotangra.com


More information about the freebsd-questions mailing list