Changing date format

Hi,

Is there any way to change one date format to another ?? I mean I have a file having dates in the format (Thu Sep 29 2005) ... and i wud like to change these to YYYYMMDD format .. is there any command which does so ?? Or anything like enum which we have in C ??

Thanks in advance,

Sabari Nath S

You did not mention which OS

The following works well for GNU date.

sh-2.05b$ cat sabri.ksh 
#! /bin/ksh
epoch=$(date -d "Thu Sep 29 2005" +%Y%m%d)
echo $epoch
sh-2.05b$ ./sabri.ksh 
20050929

Hi Vino ...

this is the version of the OS I am using ..

$ version
Machine hardware: sun4u
OS version: 5.9
Processor type: sparc
Hardware: SUNW,Sun-Fire

And its not accepting -d option for date command ...

$ date -d "Thu Sep 29 2005" +%Y%m%d
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]

I had written a small script to change such dates into YYYYMMDDHHMMSS

See this post

You need to modify that to remove the HHMMSS

Thanks Vino ... i modified that and it works fine for me .....
Now I am getting a list of dates as result from some long command and i am piping that to xargs -l1 sabri.ksh ; and getting the conversion done ... thx a lot ...

but still let me ask just out of curiosity tht do we have any thing like enum in unix or awk so that i can avoid using a ksh script and do that in command line itself .....

Something like a one-liner ? I doubt it.

Even if it in awk, it would go into few lines.

As for enum in shell scripting, I dont know it is available. If at all, it is present, then awk could have it, since it has a syntax which resembles C syntax.