Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 16: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, 12: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

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