davegimo

dateeee

Feb 11th, 2021
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from datetime import date, timedelta, datetime
  2. a = "20210201"
  3. date = datetime.strptime(a, '%Y%m%d')
  4.  
  5. last_day_of_prev_month = date.replace(day=1) - timedelta(days=1)
  6. start_day_of_prev_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)
  7. b = start_day_of_prev_month.strftime('%Y%m%d')
  8. # For printing results
  9. print(a)
  10. print(b)
  11.  
RAW Paste Data