I have some string dates ı try to calculate how much day have from today to string day example string dates
examples=["June 30 - July 16","Thursday, July 15","July 9 - 19"]
I write for one type
import datetime
arriveTimes="June 30 - July 16"
dates=arriveTimes.split(" - ")
monthToNumber = {
'January' : 1,
'February' : 2,
'March' : 3,
'April' : 4,
'May' : 5,
'June' : 6,
'July' : 7,
'August' : 8,
'September' : 9,
'October' : 10,
'November' : 11,
'December' : 12}
firstMounth=""
arriveTimesOnDayList=[]
for date in dates:
month,day=date.split(" ")
month=str([v for k, v in monthToNumber.items() if month.lower() in k.lower()][0])
today = datetime.datetime.now()
year=str(today.year)
dateTimeObj = datetime.datetime.strptime(year+"-"+month+"-"+day, '%Y-%m-%d')
arriveTimeDatetimeObj = dateTimeObj - today
arriveTimesOnDayList.append(str(arriveTimeDatetimeObj.days))
print(arriveTimesOnDayList)
arriveTimesOnDayStr=arriveTimesOnDayList[0]+"-"+arriveTimesOnDayList[1]
print(arriveTimesOnDayStr)
but I want it support all type
June 27, what is the expected result when example isJune 30 - July 16? 2 or 18 or some time between? Perhaps you should add more examples to show what all type you want, and expected results for all of your examples to make it clear. By the way, I think your current code doesn't work.