Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    2

    Unanswered: 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

  2. #2
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •