Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi friends,
I am executing a SQL through UNIX. I receive a date from SQL and store it in a variable in unix. The date is in (13-AUG-2009) format. But i need this to be in YYYYMMDD(20090813). Kindly help me in converting the date format in UNIX

My OS is Solaris so I'm using nawk with the korn shell:
#!/bin/ksh yourdate="13-AUG-2009" newdate=$(echo "$yourdate"|nawk ' BEGIN { FS="-" } { mm=month_no($2) printf("%s%02d%02d", $3, mm, $1) } function month_no(mm) { if(mm == "JAN") return 1 if(mm == "FEB") return 2 if(mm == "MAR") return 3 if(mm == "APR") return 4 if(mm == "MAY") return 5 if(mm == "JUN") return 6 if(mm == "JUL") return 7 if(mm == "AUG") return 8 if(mm == "SEP") return 9 if(mm == "OCT") return 10 if(mm == "NOV") return 11 if(mm == "DEC") return 12 return 0 }') echo $newdate

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |