I cannot figure out how to get DD and YYYY separated. For MM I did:
MMDDYYYY = int(input("enter" ))
month = MMDDYYYY // 1000000
Tried using % but could not figure out where to place it.
CodePudding user response:
Use the modulus operator in conjunction with division (try online)
month = MMDDYYYY // 1000000
day = MMDDYYYY % 1000000 // 10000
year = MMDDYYYY % 10000
print(month, day, year)
CodePudding user response:
Instead of trying to do math, cutting the string should be easier (if you know it will be in MMDDYYYY
format):
MMDDYYYY = input("enter: ")
month = int(MMDDYYYY[:2])
day = int(MMDDYYYY[2:4])
year = int(MMDDYYYY[4:])
CodePudding user response:
Python has a very powerful class for dates and times called datetime
, you can benefit well from it.
here are some links to help:
https://www.programiz.com/python-programming/datetime
https://www.w3schools.com/python/python_datetime.asp
and here is the documentation:
https://pypi.org/project/DateTime/