Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert date and time stamps from Epoch #829

Open
ethman42 opened this issue May 1, 2017 · 5 comments
Open

Convert date and time stamps from Epoch #829

ethman42 opened this issue May 1, 2017 · 5 comments

Comments

@ethman42
Copy link

ethman42 commented May 1, 2017

I would love to have a feature that would let me convert epoch timestamps to human-readable. Any thoughts on getting this working.

@jpmckinney
Copy link
Member

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.

@jpmckinney jpmckinney changed the title Convert sate and time stamps from Epoch Convert date and time stamps from Epoch May 26, 2017
@jpmckinney
Copy link
Member

No other interest expressed since 2017, and no easy solution for this feature, so closing.

@tb582
Copy link

tb582 commented Aug 25, 2021

re-opening this, wondering if any python or other advancements make this more supportable?

@tb582 tb582 mentioned this issue Aug 25, 2021
@jpmckinney
Copy link
Member

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.

@jpmckinney jpmckinney reopened this Sep 14, 2021
@damonmcminn
Copy link

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.csv strips 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 |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants