关于日期计算进位的问题

VCGuru2003 2003-10-16 11:32:14
比如说我一个起日期是2003-10-16号,我要对他加3个月,计算止日期,或者加4个月计算止日期,或者五个月,这样就涉及到日期的进位问题,对这种进位的处理要怎么处理,有相关的函数嘛
...全文
124 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hkzhou 2003-10-16
  • 打赏
  • 举报
回复
对了 li_month<0应该为li_month<=0
_________________________
(我以前写过一个,源代码找不到了,我评记忆写的,楼主可以测试一下
hkzhou 2003-10-16
  • 打赏
  • 举报
回复
试试这个
date为指定的时间
year 为要加减的年份
month 为要加减的月份
day 为要加减的天
________________________________________
function dataadd(date,year,month,day)
integer li_year,li_month,li_day,n
string ls_date
li_year=year(date)
li_month=month(date)
li_day=day(date)
li_year=li_year+year
li_month=month+li_month
if li_month<0 then
n=abs(li_month)/12+1
li_year=li_year-n
li_month=n*12+li_month
else
n=abs(li_month)/12
li_year=li_year+n
li_month=li_month-12*n
end if
date=date(string(li_year)+"-"+string(li_month)+"-"+string(li_day))
date=RelativeDate(date, day)

return date
____________
flyhot 2003-10-16
  • 打赏
  • 举报
回复
学习
hkzhou 2003-10-16
  • 打赏
  • 举报
回复
学习
VCGuru2003 2003-10-16
  • 打赏
  • 举报
回复
我先测试一下,等下给分
double22822 2003-10-16
  • 打赏
  • 举报
回复
不是我写的。
/*****************************************************
功能:把一个日期部分加到另一个日期后产生的日期
函数名:gf_dateadd(string as_condition,integer ai_number,date_ad_date)
参数说明:string as_condition :判断是日,月,年相加
integer ai_number :日,月,年的一个整数值
date ad_date:原日期
*********************************************************/
date ld_return //返回值
int li_month,li_year,li_mod
IF as_condition = 'dd' THEN //日相加
ld_return = RelativeDate(ad_date, ai_number)
ELSEIF as_condition = 'mm' THEN //月相加
li_month = month(ad_date) + ai_number //将原日期的月加上所求的月份数
li_mod = mod(li_month,12)
li_year = int(li_month/12)
if li_mod = 0 then
li_year = year(ad_date) + li_year - 1
li_month = 12
ld_return = date(string(li_year) + '/12/' + string(day(ad_date)))
elseif li_mod > 0 then
li_year = year(ad_date) + li_year
ld_return = date((string(li_year) + '/' + string(li_mod) + '/' + string(day(ad_date))))
else
li_year = year(ad_date) + li_year
li_month = 12 - li_mod
ld_return = date(string(li_year) + '/' + string(li_month) + '/' + string(day(ad_date)))
end if

ELSEIF as_condition = 'yy' THEN //年相加
li_year = year(ad_date) + ai_number
ld_return = date(replace(string(ad_date),1,4,string(li_year)))
ELSE
messagebox("提示信息","第一个参数调用错误!")
END IF

return ld_return

1,079

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧