1825721 Members
3134 Online
109687 Solutions
New Discussion

Converting date output

 
SOLVED
Go to solution
Jeff Picton
Regular Advisor

Converting date output

Hi

I have a part of a script which outputs the date as 03/08/11 to represent 11th August 2003.

How can I set the date variable so that this is output as 11 Aug 2003
12 REPLIES 12
Pete Randall
Outstanding Contributor

Re: Converting date output

Would "date +'%d/%m/%y'" provide what you're looking for?


Pete


Pete
Sergejs Svitnevs
Honored Contributor

Re: Converting date output

FORMAT controls the output.

# date "+%d %b %Y"

Regards,
Sergejs
T G Manikandan
Honored Contributor

Re: Converting date output

date -u +"%d %B %Y"
T G Manikandan
Honored Contributor

Re: Converting date output

it should be small case 'b' for your request

$date -u +"%d %b %Y"
Pete Randall
Outstanding Contributor

Re: Converting date output

Sorry, Jeff, I missed the "non-decimal month part. Obviously, the other solutions are more what you're after!


Pete


Pete
Jeff Picton
Regular Advisor

Re: Converting date output

Hi

Thanks for all the answers. Let me clarify this one a little.

I do

date1=`lifls -l /tmp/LIF | grep HPUX | awk '{print$6}'`

echo $date1 gives 03/08/11. Does these answers convert this date ?
Thierry Poels_1
Honored Contributor
Solution

Re: Converting date output

hi,

try something like:

echo 10/01/03 | awk -F'/' '{print $2 substr ("JanFebMarAprMayJunJulAugSepOctNovDec", ($1 -1 ) * 3 + 1,3) $3}'


good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Thierry Poels_1
Honored Contributor

Re: Converting date output

oooops, forgot the spacing and 2003 instead of 03:

echo 10/01/03 | awk -F'/' '{print $2 " " substr ("JanFebMarAprMayJunJulAugSepOctNovDec", ($1 -1 ) * 3 + 1,3) " 20" $3}'

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Thierry Poels_1
Honored Contributor

Re: Converting date output

aaaarrrgh, not easy if you can't see all replies when replying -- fields in wrong order :

echo 03/08/11 | awk -F'/' '{print $3 " " substr ("JanFebMarAprMayJunJulAugSepOctNovDec", ($2 -1 ) * 3 + 1,3) " 20" $1}'

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Jeff Picton
Regular Advisor

Re: Converting date output

Hi everyone

Many thanks for the replies. After I clarified my problem, It was Thierry who gave me a workable solution.

Jeff
RolandH
Honored Contributor

Re: Converting date output

Hi Thierry,

I like your solution. Very tricky and very small instead to compare and replace.

I would give you 10 Points.

Roland
Sometimes you lose and sometimes the others win
Tim Sanko
Trusted Contributor

Re: Converting date output

Thiery,

Very smooth. I have filed off the serial number and called it my own...

Tim