python3获取两个日期之间所有日期,以及比较大小的实例
作者:我的光荣 时间:2023-01-31 06:54:52
如下所示:
import datetime
#获取两个日期间的所有日期
def getEveryDay(begin_date,end_date):
date_list = []
begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
end_date = datetime.datetime.strptime(end_date,"%Y-%m-%d")
while begin_date <= end_date:
date_str = begin_date.strftime("%Y-%m-%d")
date_list.append(date_str)
begin_date += datetime.timedelta(days=1)
return date_list
print(getEveryDay('2016-01-01','2017-05-11'))
import datetime
#比较大小
strftime = datetime.datetime.strptime("2017-11-02", "%Y-%m-%d")
strftime2 = datetime.datetime.strptime("2017-01-04", "%Y-%m-%d")
print("2017-11-02大于2017-01-04:",strftime>strftime2)
来源:https://blog.csdn.net/qq_34369025/article/details/78181909
标签:python,获取,日期
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL慢查询日志的作用和开启
2024-01-21 20:23:33
fckeditor编辑器在php中的配置方法
2023-10-14 14:26:52
使用SQL Server 2008中对象相关性
2008-12-12 06:36:00
mysql简单实现查询结果添加序列号的方法
2024-01-26 11:33:56
Python中logging日志库实例详解
2023-10-04 13:26:25
Python matplotlib以日期为x轴作图代码实例
2021-08-17 03:41:09
![](https://img.aspxhome.com/file/2023/9/109599_0s.jpg)
Python实现微信好友数据爬取及分析
2021-09-30 04:51:55
![](https://img.aspxhome.com/file/2023/9/101599_0s.jpg)
python使用turtle库与random库绘制雪花
2021-02-21 22:51:20
![](https://img.aspxhome.com/file/2023/4/72854_0s.jpg)
python 随机生成10位数密码的实现代码
2021-08-01 23:49:02
给Python初学者的一些编程技巧
2023-05-27 21:41:30
php使用socket简单实现通信功能
2023-05-31 13:01:23
![](https://img.aspxhome.com/file/2023/5/55295_0s.png)
使用canal监控mysql数据库实现elasticsearch索引实时更新问题
2024-01-20 22:48:39
![](https://img.aspxhome.com/file/2023/2/91452_0s.png)
详解python中递归函数
2022-04-17 19:40:55
JS实现炫酷雪花飘落效果
2024-04-16 10:36:54
![](https://img.aspxhome.com/file/2023/7/136597_0s.jpg)
python开发之list操作实例分析
2023-04-17 16:07:33
pytorch 实现模型不同层设置不同的学习率方式
2023-11-20 00:29:25
go日志库logrus的安装及快速使用
2024-04-26 17:31:40
成功实现ajax,xmlhttp跨域访问(php,asp,jsp)
2008-02-13 18:40:00
安装Pycharm2019以及配置anconda教程的方法步骤
2021-10-04 18:43:08
![](https://img.aspxhome.com/file/2023/3/117953_0s.png)
MyEclipse连接Mysql数据库的方法(一)
2024-01-23 11:31:29
![](https://img.aspxhome.com/file/2023/4/68674_0s.png)