2011-11-02
两年后是哪一天该怎么计算
------解决方案--------------------
- C/C++ code
global function date f_dateadd (string as_type, date ad_date, integer ai);//在向指定日期加上一段时间的基础上,返回新的date值(与MSSQL的dateadd函数类似)int listring lsdate ldif ai = 0 then return ad_datechoose case lower(as_type) case 'year','yy','yyyy' //年份 li = year(ad_date) + ai if li < 1900 or li > 3000 then return 1900-01-01 ls = string(li) + string(ad_date, '-mm-dd') case 'quarter','qq','q' //季度 li = month(ad_date) + 3 * ai ls = string(year(ad_date) + int((li -1) / 12)) + string(mod(li, 12) - 6 * (sign(li) - 1), '-00') + string(ad_date, '-dd') case 'month','mm','m' //月份 li = month(ad_date) + ai ls = string(year(ad_date) + int((li -1) / 12)) + string(mod(li, 12) - 6 * (sign(li) - 1), '-00') + string(ad_date, '-dd') case 'day','dd','d' //天数 return RelativeDate ( ad_date, ai ) case 'week','wk','ww' //周数 return RelativeDate ( ad_date, ai * 7 ) case else return ad_dateend chooseif ls = '1900-01-01' then return 1900-01-01ld = date(ls)if ld = 1900-01-01 then ld = f_dateadd('dd', f_dateadd('mm', date(left(ls, 8) + '01'), 1), -1)return ldend function