[NTLUG:Discuss] How do I set Date in Filename in Bash

Patrick R. Michaud pmichaud at pobox.com
Mon Feb 16 08:45:03 CST 2004


On Mon, Feb 16, 2004 at 09:46:57AM -0600, Dennis wrote:
> I read man date, and see the various flags. I need to name directories
> like: 02.16.04, but the closest I see using date's flags is:
> MYDATE=`date +%D` which give 02/16/04.
> How do I change the '/' to '.'? 


MYDATE=$(date '+%m.%d.%y')

You can put whatever characters you want in the date '+' string, only
the percent signs get converted.  So, for example:

   date '+%y-%m-%d %Hh%M' 

will give dates in the form '04-02-16 08h44'.

Pm



More information about the Discuss mailing list