从熊猫日期范围功能中删除时间

时间:2021-02-05 15:37:58

标签: python pandas function datetime

我使用熊猫测距仪计算了一个日期范围:

max_date_column = ws.max_column
last_date_entered = ws.cell(row=1, column=max_date_column).value
todays_date = datetime.date.today()
Date_difference = pd.date_range(start= last_date_entered, end=todays_date, freq='D')
print("last date entered was ")
print(last_date_entered)
print("todays date is ")
print(todays_date)
print("the days not done are")
print(Date_difference)
for date in Date_difference:
 print(date)

它给我的打印结果如下图所示。 我的问题是,当我将其放入 HTML 时,它包含时间。我不想要时间,我只想要约会。我怎样才能摆脱时间?

我通过以下方式将其输入到我的 html 中:

{% for date in Date_difference %}
<h5>{{ date }}</h5>
{% endfor %}

当我这样做时,它会在屏幕上显示以下内容:

Jan. 28, 2021, midnight
Jan. 29, 2021, midnight
Jan. 30, 2021, midnight
Jan. 31, 2021, midnight
Feb. 1, 2021, midnight
Feb. 2, 2021, midnight
Feb. 3, 2021, midnight
Feb. 4, 2021, midnight
Feb. 5, 2021, midnight 

enter image description here

1 个答案:

答案 0 :(得分:0)

使用 datetime.datetime.now().date() 方法。

打印(日期.日期())