Search code examples
pythonepoch

Convert date in words to epoch time stamp in python


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?


Solution

  • 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']
    ]