Convert date and time stamps from Epoch
I would love to have a feature that would let me convert epoch timestamps to human-readable. Any thoughts on getting this working.
csvkit offers --date-format and --datetime-format for parsing dates/times, but apparently Python's strptime doesn't support %s (which in other languages allows the parsing of timestamps). So, we'll have to pursue a special case.
No other interest expressed since 2017, and no easy solution for this feature, so closing.
re-opening this, wondering if any python or other advancements make this more supportable?
Still nothing in Python: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
This feature would require new logic to use date.fromtimestamp, but it's not a simple fix like %s would have been.
It's possible to kludge it with GNU Awk strftime, assuming you manually prepend headers (to avoid the header being converted to a datetime) eg:
Given input.csv of:
a,b,c,d
foo,bar,1674642543,baz
spam,eggs,1674645576,ham
the following can be used:
tail -n+2 input.csv |
awk -F, '{ print $1 "," $2 "," strftime("%c",$3) "," $4 }' |
sed -e "1i $(head -n1 input.csv)" |
csvlook
where:
-
tail -n+2 input.csvstrips the headers -
awk -F, '{ print $1 "," $2 "," strftime("%c",$3) "," $4 }'transforms the timestamp -
sed -e "1i $(head -n1 input.csv)"prepends the headers
resulting in:
| a | b | c | d |
| ---- | ---- | ---------------------------- | --- |
| foo | bar | Wed 25 Jan 2023 10:29:03 GMT | baz |
| spam | eggs | Wed 25 Jan 2023 11:19:36 GMT | ham |