7

I have the below code which works out the date 6 months ago from todays date.

import datetime
from dateutil.relativedelta import relativedelta
from datetime import date

six_months = date.today() + relativedelta(months=-6)  

However I would like six_months to be in "%Y%m%d" format.

Thank you for your help.

Robert Miller
  • 81
  • 1
  • 1
  • 5

1 Answers1

15

You're looking for strftime.

six_months.strftime('%Y%m%d') 

This should do the job for you.

Anomitra
  • 1,111
  • 15
  • 31