2

Lets say I have a program that will run every 3 months, I want it to create a new folder with the name 2022Quarter1. Then when I run it again 3 months later, I want it to say 2022Quarter2, etc. Then when a new year comes in, that new year first quarter will be called 2023Quarter1, and so on.

I wrote this part of the program, just so I have an idea of what I want my end goal to be:

import os

for i in range(4):
    i+=1
    num=i
    
try:
    os.makedirs(f'C:/users/desktop/quarters/{yearNum}Quarter{num}')
except FileExistsError:
    # directory already exists
    pass
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 2
    Using Python's `datetime` you could get the current year and quarter. Also, see this question: [Is there a Python function to determine which quarter of the year a date is in?](https://stackoverflow.com/questions/1406131/is-there-a-python-function-to-determine-which-quarter-of-the-year-a-date-is-in) – aaossa Feb 18 '22 at 22:05

1 Answers1

1

You can get around this by using Python's datetime module:

  • Current date: current_date = datetime.datetime.today()
  • Current year: current_year = current_date.year
  • Current quarter: current_quarter = 1 + (current_date.month - 1) // 3
aaossa
  • 3,763
  • 2
  • 21
  • 34