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.
The function you’re looking for is called
mktime(). You should use thegensub()function to manipulate the datespec into the format that can be read bymktime().To format the second example that you give, consider:
Results on my machine:
To format the first example that you give, consider:
Results on my machine:
For more information, please consult the manual, specifically time functions and string functions. HTH.