#python有day相減的函式datetime.datetime.timedelta()但是沒有月相減的,蛋疼,自己來吧,達到目的就行了,我只要2013-02-10這樣的格式就#ok了,把時間格式化成這樣不難吧,接下來就簡單了~\(≧▽≦)/~啦啦啦,處理字串就行了,然後就有了下面的函式#只是得到上乙個月哦,我的目的達到了,如果你想得到上幾個月的,就自己改改吧,或者寫個迴圈,~\(≧▽≦)/~啦啦啦def _minus_moths(_time):
_time_arr = _time.split('-')
_tyears = int(_time_arr[0])
_tmonth = int(_time_arr[1])-1
if _tmonth==0:
_tmonth = _tmonth + 12
_tyears = _tyears - 1
return str(_tyears)+'-'+str(_tmonth)+'-'+_time_arr[2]
#coding by seay
print(_minus_moths('2013-01-20'))
Python datetime日期相減
python中需要計算時間間隔,使用該方法能夠計算出相差的days和seconds from datetime import datetime supp date str datetime.now split 0 print str datetime.now split 0 days datetim...
oracle 日期相減
oracle日期相減 2012 02 10 12 18 months between date2,date1 給出date2 date1的月份 sql select months between 19 12月 1999 19 3月 1999 mon between from dual mon bet...
python 日期相減得天數差
import datetime def straight minus date1 date2 flag 3 while 1 date1 input please input the fisrt date like,format like 20180808 n t date2 input please...