Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python比较两个日期_Python - Fatal编程技术网

使用Python比较两个日期

使用Python比较两个日期,python,Python,上面的代码在任何在线python编译器中都可以正常运行,但每当我在服务器上运行它时,都会得到如下错误: “AttributeError:class'org.python.modules.time'没有属性'strtime' 请注意,我不允许使用datetime模块或其函数,因为如果使用YYYY-MM-DD(年-月-日),我将得到新的错误“ImportError:没有名为datetime的模块”设置日期字符串的格式,您可以将它们作为字符串按字典顺序进行比较。字符的字典顺序将与时间顺序一致。您甚至不

上面的代码在任何在线python编译器中都可以正常运行,但每当我在服务器上运行它时,都会得到如下错误: “AttributeError:class'org.python.modules.time'没有属性'strtime'


请注意,我不允许使用datetime模块或其函数,因为如果使用YYYY-MM-DD(年-月-日),我将得到新的错误“ImportError:没有名为datetime的模块”

设置日期字符串的格式,您可以将它们作为字符串按字典顺序进行比较。字符的字典顺序将与时间顺序一致。您甚至不需要为此导入模块


假设日期字符串的长度相同(必要时用前导零填充),并且它们使用相同的分隔符。

您是否尝试过datetime模块?它可以满足您的需要…您是否搜索了您正在运行的版本?python的版本是python 2.3是否有任何方法或命令将datetime模块包含到库中而不卸载当前安装的pyhton版本
import time

date1 = "31/12/2015"
date2 = "01/01/2019"


newdate1 = time.strptime(date1, "%d/%m/%Y")
newdate2 = time.strptime(date2, "%d/%m/%Y")


if newdate1 > newdate2:
    print "Certificate got Expired on ",date1
else:
    print "Certificate will be expired on ",date2