Uncategorized

formatting – Create python previous date folder, declaring strftime with space between %b and %Y


Hi am a newbie in phyton, anybody could help me because am declaring strftime on how to put blank spaces between the dates without hypenations, as of now I’m making a script that creates a folder based on previous time.

Please check my code.
from datetime import datetime, date

oneday = datetime.timedelta(days-1)
yesterday = datetime.date.today() - oneday
path = "G:"
current_time = yesterday.strftime('%Y\%b %Y\%Y-%m-%d')
command = mkdir {0}".format(current_time)
os.chdir(path)
os.system(command)

the script output should create directory as follows:

2024
  - Jan 2024 <== subfolder of 2024
    - 2024-01-11 <==subfolder of Jan 2024

Thanks.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *