python指定日期后加几天判断

#!/usr/bin/python

import datetime
import sys

arg1_list=list(sys.argv[1].split(','))
arg2_list=list(sys.argv[2].split(','))
if len(arg2_list) != 2:
    sys.exit(1)

#201705222300
TIME_START=arg2_list[0]
#201705230100
TIME_END=arg2_list[1]
#20170522
START_DATE=TIME_START[0:8]
#2017-05-22
START_DATE_FORMAT='{0}-{1}-{2}'.format(TIME_START[0:4],TIME_START[4:6],TIME_START[6:8])
#20170523
END_DATE=TIME_END[0:8]
#2017-05-23
END_DATE_FORMAT='{0}-{1}-{2}'.format(TIME_END[0:4],TIME_END[4:6],TIME_END[6:8])
#2017-05-22 23:00
START_TIME_UNIX='{0}-{1}-{2} {3}:{4}:00'.format(TIME_START[0:4],TIME_START[4:6],TIME_START[6:8],TIME_START[8:10],TIME_START[10:12])
#2017-05-23 01:00
END_TIME_UNIX='{0}-{1}-{2} {3}:{4}:00'.format(TIME_END[0:4],TIME_END[4:6],TIME_END[6:8],TIME_END[8:10],TIME_END[10:12])

d1 = datetime.datetime(int(TIME_START[0:4]), int(TIME_START[4:6]), int(TIME_START[6:8]))
d2 = datetime.datetime(int(TIME_END[0:4]), int(TIME_START[4:6]), int(TIME_END[6:8]) )
offset=(d2 - d1).days

print offset
if offset == 0:
    DAYNUM="1"
elif offset == 1:
    DAYNUM="2"
elif offset == 2:
    DAYNUM="3"

print DAYNUM
posted @ 2017-05-22 11:41  苏小北1024  阅读(2008)  评论(0编辑  收藏  举报