`what is the index of the second "/" in a date.
date = input('write todays date: ')
i = date.find('/')
month = date\[:i]
day =??????
year = ???????
print(f' todays month is {month}')
I tried all my knowledge did not work`
`what is the index of the second "/" in a date.
date = input('write todays date: ')
i = date.find('/')
month = date\[:i]
day =??????
year = ???????
print(f' todays month is {month}')
I tried all my knowledge did not work`
I would suggest you use datetime
to perform parsing and formatting, in this case using datetime.strptime
>>> from datetime import datetime
>>> dt = datetime.strptime('12/25/2009', '%m/%d/%Y')
>>> dt
datetime.datetime(2009, 12, 25, 0, 0)
>>> dt.month, dt.day, dt.year
(12, 25, 2009)
The Python method find
takes optional arguments. You can pass the start index to look for. In your case the start would be the end index of the first match.
Example:
first = date_str.find("/")
if (first == -1):
# not found
second = date_str.find("/", first + 1)
...
If I am understanding your question correctly, the second "/" in that date format would be index 2 if you were looking at that string as a zero based array.
So I say... 2