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

34,827

Solution 1

This is what finally worked on unix(solaris).

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

returned: 04-NOV-2009

Solution 2

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.

Solution 3

You could uppercase it yourself if caret uppercase is not supported in your environment:

date '+%d-%h-%Y' | tr 'a-z' 'A-Z'
Share:
34,827
AieshaDot
Author by

AieshaDot

Jesus Lover, Programmer, Technology Lover, Longtime Geek, Micropreneur, and Blogger. www.thoughtsplash.com

Updated on July 09, 2022

Comments

  • AieshaDot
    AieshaDot almost 2 years

    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?

  • AieshaDot
    AieshaDot over 14 years
    @Mark Rushakoff - This doesn't work on both uxix or linux. I get the following when I execute: 04-^Nov-2009.
  • AieshaDot
    AieshaDot over 14 years
    @martin clayton - This syntax worked on linux but not unix and my script is running on a unix box. However, your code snippet pointed me the right direction. Thx!
  • user1066101
    user1066101 over 14 years
    Suggested "above"? Please reference a specific answer. Orders change with voting,