If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk: convert datetime format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-02-04, 15:45
keane5 keane5 is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
awk: convert datetime format

I need to convert a date and time column in a flat file from:

dd-mon-yy hh:mm:ss (24-MAY-04 23:45:18)

TO

yyyy-mm-dd hh:mm:ss (2004-05-24 23:45:18)

I am having trouble using the split command because of the timestamp. Is there a conversion function I can use in awk?

Tim
Reply With Quote
  #2 (permalink)  
Old 06-04-04, 11:37
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi keane5,
may be this can help you out. It is not an excellent solution but it works.

DATE_OLD="24-MAY-04 23:45:18"
DATE_NEW=`echo $DATE_OLD | awk ' BEGIN { FS="@"}
{
day=substr($1, 1, 2)
month=substr($1, 4, 3)
year=substr($1, 8, 2)
time=substr($1, 11, 8)

if (month == "MAY" )
{
month = "05"
}
# ..... and so on for every month from JAN to DEZ

print "20"year"-"month"-"day" "time
}'`
echo $DATE_NEW
__________________
Greetings from germany
Peter F.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On