【发布时间】:2017-12-30 08:44:06
【问题描述】:
我对 Python 编码非常陌生。我试图获取一个月的开始日期和结束日期,然后将其与同一个 Excel 中的另一个日期列进行比较。
我只需要mm/dd/yy 格式的日期,不需要时间。
final_month_end_date 基本上是一种字符串格式,我将其与实际日期进行比较,但它给了我一个错误提示
"TypeError: 无法将类型 'Timestamp' 与类型 '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)
【问题讨论】:
标签: python datetime timestamp type-conversion strftime