Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:32:43+00:00 2026-06-17T21:32:43+00:00

Gnu AWK provides the built in function strftime() which can convert a timestamp like

  • 0

Gnu AWK provides the built in function

strftime()

which can convert a timestamp like 1359210984 into Sat 26. Jan 15:36:24 CET 2013.
I couldn’t find a function that would do this:

seconds = timefromdate("Sat 26. Jan 15:36:24 CET 2013", "%a %d. %b %H:%M:%S CET %Y")

or

seconds = timefromdate("2013-01-26 15:36:24", "%Y-%m-%d %H:%M:%S")

Whereas seconds then is 1359210984.

So, the date string should be convertable by a format pattern.

I’d like to do this in gawk only.

Edit 1:

I’d like to convert the date only in gawk for further processing of the stream.

Edit 2:

I’ve clarified my question. It was a bit sloppy in the "would do this" code example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:32:44+00:00Added an answer on June 17, 2026 at 9:32 pm

    The function you’re looking for is called mktime(). You should use the gensub() function to manipulate the datespec into the format that can be read by mktime().


    To format the second example that you give, consider:

    BEGIN {
        t = "2013-01-26 15:36:24"
        f = "\\1 \\2 \\3 \\4 \\5 \\6"
    
        s = mktime(gensub(/(....)-(..)-(..) (..):(..):(..)/, f, "", t))
    
        print s
    }
    

    Results on my machine:

    1359178584
    

    To format the first example that you give, consider:

    BEGIN {
        t = "Sat 26. Jan 15:36:24 CET 2013"
    
        gsub(/\.|:/, FS, t)
        split(t,a)
    
        Y = a[8]
        M = convert(a[3])
        D = a[2]
    
        h = a[4]
        m = a[5]
        s = a[6]
    
        x = mktime(sprintf("%d %d %d %d %d %d", Y, M, D, h, m, s))
    
        print x
    }
    
    function convert(month) {
    
        return(((index("JanFebMarAprMayJunJulAugSepOctNovDec", month) - 1) / 3) + 1)
    }
    

    Results on my machine:

    1359178584
    

    For more information, please consult the manual, specifically time functions and string functions. HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Debian 6 and GNU sed, trying to get awk to convert the
GNU Date lets you convert date strings like so: $ date +%d %m %Y
I am trying to call gawk (the GNU implementation of AWK) from Python in
GNU Emacs 23.1.1 Fedora 13 I can select the colour theme by M-x color-theme-select
Using GNU sed , I need to remove parenthetical phrases like (click here ....)
Using GNU bash (version 4.0.35(1)-release (x86_64-suse-linux-gnu), I would like to negate a test with
I was wondering if, with egrep ((GNU grep) 2.5.1), I can select a part
GNU 23.1.1 By clicking the F5 button I can compile my project. However, I
In GNU Octave you can make a picture where different colors represent different values
In GNU Octave version 3.4.3, I am having trouble applying a custom function to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.