Computing.Net > Forums > Unix > UNIX/changing date format

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

UNIX/changing date format

Reply to Message Icon

Name: Sabs
Date: August 17, 2009 at 05:06:43 Pacific
OS: Windows XP
Product: Digi international Etherlite 32 enet 32rj45 tcp/ip nt unix java
Subcategory: General
Tags: UNIX, Date Format, date formatting
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 17, 2009 at 07:10:48 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: UNIX/changing date format

change date format using shell www.computing.net/answers/unix/change-date-format-using-shell/6741.html

Time diff and date formatting prob www.computing.net/answers/unix/time-diff-and-date-formatting-prob/5065.html

Prb in Yest'days Date Format www.computing.net/answers/unix/prb-in-yestdays-date-format/4559.html