[英]How to only output the days (without hours, minutes, and seconds) while using time delta?
I have a function:我有一个功能:
def diffDate(YYYY,MM,DD):
tgl = date(YYYY,MM,DD)
skrg = datetime.date(datetime.now())
if tgl <= skrg:
diffDate = skrg - tgl
elif tgl >= skrg:
diffDate = tgl - skrg
return diffDate
The output will be "x days, 0:00:00".输出将为“x 天,0:00:00”。 How to only output the days without the hours, minutes, and seconds?
如何只输出没有小时、分钟和秒的天数? And can I multiple the day difference with integer without taking the 'days' ?
我可以在不取“天”的情况下用整数乘以天数差异吗? *Sorry for my bad english
*对不起,我的英语不好
You can do multiple steps in one:您可以合二为一地执行多个步骤:
datetime import date
def absoluteDaysToNow(yyyy, mm, dd):
delta = date.today() - date(yyyy, mm, dd)
return abs( delta.days )
See: python docs, built-in function abs() , date example: days difference请参阅:python 文档,内置函数 abs() , 日期示例:天数差异
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.