-2

I have a Dictionary in the following Format

{'Date': ['May 22', 'Apr 22', 'Mar 22', 'Feb 22', 'Jan 22']}

I need to convert the date values to epoch timestamps. How do I convert the data in this format to the epoch time stamp in seconds?

Mathew Pius
  • 65
  • 1
  • 7
  • By guessing the year? How would you determine what the correct result should be? – tripleee May 01 '22 at 10:58
  • 1
    have a look at this tutorial, I am not sure but I think that your dictionary is not enough to find the epoch. https://www.geeksforgeeks.org/convert-python-datetime-to-epoch/ – serax May 01 '22 at 10:58
  • What if the data is in the format {'Date': ['May 01, 2022', 'Apr 30, 2022', 'Apr 29, 2022', 'Apr 28, 2022', 'Apr 27, 2022']} ? Is it possible to convert this data? – Mathew Pius May 01 '22 at 11:04

1 Answers1

1

With the input from the comment you could try:

from datetime import datetime

dates = {'Date': ['May 01, 2022', 'Apr 30, 2022', 'Apr 29, 2022', 'Apr 28, 2022', 'Apr 27, 2022']}
dates['Date'] = [
    datetime.strptime(date, "%b %d, %Y").timestamp() for date in dates['Date']
]
Timus
  • 10,974
  • 5
  • 14
  • 28