shell

#!/bin/bash
start_date="20210917"
end_date="20211116"
while [ "$start_date" -le "$end_date" ];
do
  stat_date=`date -d "$start_date" +%Y-%m-%d`
  echo $stat_date
  start_date=$(date -d "$start_date+1days" +%Y%m%d)
done   

python

# 方法1:
import datetime
def main():
    begin = datetime.date(2014,6,1)
    end = datetime.date(2014,6,7)
for i in range((end - begin).days+1):
    day = begin + datetime.timedelta(days=i)
    print str(day)
if __name__ == '__main__':
    main()
# 方法2:

import datetime
begin = datetime.date(2014,6,1)
end = datetime.date(2014,6,7)
d = begin
delta = datetime.timedelta(days=1)
while d <= end:
    print d.strftime("%Y-%m-%d")
    d += delta

# 方法3:
import datetime
def daterange(d1, d2):
    return (d1 + datetime.timedelta(days=i) for i in range((d2 - d1).days + 1))
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐