Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

date

shell

unix

ksh

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

I have tried the following:

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

It returns 04-Nov-2009 I need for the Nov to be NOV (all caps). Can this be done with the date utility?

like image 965
AieshaDot Avatar asked Dec 17 '22 05:12

AieshaDot


2 Answers

This is what finally worked on unix(solaris).

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

returned: 04-NOV-2009

like image 104
AieshaDot Avatar answered Feb 22 '23 23:02

AieshaDot


The ^ character forces uppercase in the GNU coreutils date (at least, it does in version 6.9.92.4 of coreutils):

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

Unfortunately, ^ is not POSIX standard for date, so you'll probably have to resort to a second command such as the tr suggested by @martin clayton, if you aren't on a GNU system.

like image 22
Mark Rushakoff Avatar answered Feb 22 '23 23:02

Mark Rushakoff