Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to convert date passed as a variable in the format
'DD-MON-YY' i.e., '31-JUL-08' to 'YYYYMMDD' format
'20080731' . Someone gimme a single line command. Anybody here, help...!TIA
TIA
Covina

If someone can post from the otherway, it's fine with me, i.e., convert from 'YYYYMMDD' to 'DD-MON-YY'.
TIA
Covina

You'll never do this in one line because of having to convert the year string to a number:
#!/bin/ksh# This korn shell function receives a date of the format
# 01-AUG-08 and returns a string YYYYMMDD
function yrmmdd
{
typeset -2Z mm
typeset -2Z yr# parse the argument into $1, $2, $3
set - $(IFS="-"; echo $1)yr=$3
dd=$1case $2 in
"JAN") mm=1;;
"FEB") mm=2;;
"MAR") mm=3;;
"APR") mm=4;;
"MAY") mm=5;;
"JUN") mm=6;;
"JUL") mm=7;;
"AUG") mm=8;;
"SEP") mm=9;;
"OCT") mm=10;;
"NOV") mm=11;;
"DEC") mm=12;;
*) echo "error"
exit ;;
esacecho "20"${yr}${mm}${dd}
} # end function
dstr=01-AUG-08retstr=$(yrmmdd $dstr)
echo $retstrIn fact, I answered a similar question for you here:

![]() |
How to identify end of li...
|
Freebsd /etc/rc.d/hostnam...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |