How to format date in KornShell script before DD-MON-YYYY?

How do I format a date in a KornShell (ksh) script on DD-MON-YYYY?

I tried the following:

date '+%d-%h-%Y' 

He returns November 04, 2009 I need NOV (all caps) to be new. Can this be done with the date utility?

+4
source share
3 answers

This is what finally worked on unix (solaris).

 date '+%d-%h-%Y' | tr [:lower:] [:upper:] 

: 04-NOV-2009

+5
source

The ^ character delays an uppercase letter in GNU coreutils date (at least in version 6.9.92.4 from coreutils):

 $ date '+%d-%^h-%Y' 04-NOV-2009 

Unfortunately, ^ is not the POSIX standard for date , so you may have to resort to a second command such as tr suggested by @martin clayton if you are not using the GNU system.

+5
source

You can make it up yourself if your environment does not support capitalization:

 date '+%d-%h-%Y' | tr 'az' 'AZ' 
+2
source

All Articles