Search code examples
python-2.7datetimetimecountdown

Converting '4 days ago' etc. to the actual dates


I have a massive spreadsheet in which all dates are written this way:

2 days ago 
9 days ago
34 days ago
54 days ago
etc.

Is there a clever Python way to convert these data to the actual dates, if I tell Python what date '1 day ago' is?


Solution

  • Use timedelta.

    Extract the value from that string in your spreadsheet and then use

    d = date.today() - timedelta(days_to_subtract)