0
我对Python编码很新颖。我试图获取一个月的开始和结束日期,然后将它与同一个Excel中的另一个日期列进行比较。如何将strftime或字符串格式转换为python中的timestamp/Date?
我只需要mm/dd/yy
格式的日期,但不需要时间。 的final_month_end_date
基本上是一个字符串格式,我与实际日期比较,但它给了我一个错误说
"TypeError: Cannot compare type 'Timestamp' with type 'str'"
我也曾尝试.timestamp()
功能,但没有用的。 我该如何解决这个问题?
import datetime as dt
import strftime
now1 = dt.datetime.now()
current_month= now1.month
current_year= now1.year
month_start_date= dt.datetime.today().strftime("%Y/%m/01")
month_end_date= calendar.monthrange(current_year,current_month)[1]
final_month_end_date= dt.datetime.today().strftime("%Y/%m/"+month_end_date)