Date format

Hi,

I need to change the date format:

Input : 31-Jan-2008
Output: 31012008

how do we achieve this?

If your date command accepts a -d argument you can get the time for a certain string:

$ date -d 31-Jan-2008
Thu Jan 31 00:00:00 CET 2008

Then you can use formatting commands with date:

date -d $yourdate +%d%m%Y
echo '31-Jan-2008'|tr '[a-z]' '[A-Z]'|sed 's/-//g;s/JAN/01/;s/FEB/02/;s/MAR/03/;s/APR/04/;s/MAY/05/;s/JUN/06/;s/JUL/07/;s/AUG/08/;s/SEP/09/;s/OCT/10/;s/NOV/11/;s/DEC/12/;'

If you are using ksh93

$ yourdate="31-Jan-2008"
$ newdate=$(printf "%(%d%m%Y)T" $yourdate)
$ print $newdate
31012008