pb 日期相关函数

//====================================================================
// 函数: gf_firstday()
//--------------------------------------------------------------------
// 描述:返回某个月的第一天
//--------------------------------------------------------------------
// 参数:日期(字符型,格式YYYYMM或者YYYYMMDD)
//--------------------------------------------------------------------
// 返回:  正确时返回输入日期所在月份的第一天,否则返回error
//--------------------------------------------------------------------
// 作者:			日期: 2010年01月04日
//====================================================================
string ls_return
ls_return="error"
if len(as_yearmon)=8 then
	ls_return=mid(as_yearmon,1,6)+"01"
elseif len(as_yearmon)=6 then
	ls_return=as_yearmon+"01"
end if
if ls_return='error' or isdate(mid(ls_return,1,4)+"-"+mid(ls_return,5,2)+"-"+mid(ls_return,7,2))=false then
	messagebox("提示","输入值不符合日期规范")
end if
return ls_return
global type gf_day_lastday from function_object
end type

forward prototypes
global function string gf_day_lastday (string as_yearmon)
end prototypes

global function string gf_day_lastday (string as_yearmon);//====================================================================
// 函数: gf_lastday()
//--------------------------------------------------------------------
// 描述:返回某个月的最后一天
//--------------------------------------------------------------------
// 参数:日期(字符型,格式YYYYMM或者YYYYMMDD)
//--------------------------------------------------------------------
// 返回:  正确时返回输入日期所在月份的最后一天,否则返回error
//--------------------------------------------------------------------
//====================================================================

string ls_return
string ls_year,ls_month
date ld_date
ls_return="error"
if len(as_yearmon)=8 and isdate(mid(as_yearmon,1,4)+"-"+mid(as_yearmon,5,2)+"-"+mid(as_yearmon,7,2))=false then
elseif len(as_yearmon)=6 and isdate(mid(as_yearmon,1,4)+"-"+mid(as_yearmon,5,2)+"-01")=false then	
else
	ls_return="ok"
end if
if ls_return='error' then
	return ls_return 
end if
ls_year=mid(as_yearmon,1,4)
ls_month=mid(as_yearmon,5,2)
if ls_month='12' then
	ls_year=string(integer(ls_year)+1)
	ls_month='01'
else
	ls_month=string(integer(ls_month)+1)
end if
ld_date=RelativeDate(Date(ls_year+'-'+ls_month+'-01'),-1)
ls_return=string(ld_date,"YYYYMMDD")
return ls_return
end function

global type gf_day_afterday from function_object
end type

forward prototypes
global function long gf_day_afterday (string as_a17s, string as_a17e)
end prototypes

global function long gf_day_afterday (string as_a17s, string as_a17e);//====================================================================
// 函数: gf_day_afterday()
//--------------------------------------------------------------------
// 描述:求出两个日期之间的天数
//--------------------------------------------------------------------
// 参数:起始日期(字符型,格式YYYYMMDD)、截止日期(字符型,格式YYYYMMDD)
//--------------------------------------------------------------------
// 返回:  整型
//--------------------------------------------------------------------
//====================================================================
long ll_return
if len(as_a17s)<>8 or len(as_a17e)<>8 or isdate(as_a17s) or isdate(as_a17e)  then 
	ll_return=-1
else
	ll_return=DaysAfter(date(left(as_a17s,4)+'-'+mid(as_a17s,5,2)+'-'+mid(as_a17s,7,2)),date(left(as_a17e,4)+'-'+mid(as_a17e,5,2)+'-'+mid(as_a17e,7,2)))
end if
return ll_return
end function

global type gf_day_newdate from function_object
end type

forward prototypes
global function string gf_day_newdate (string as_rq, integer al_ts)
end prototypes

global function string gf_day_newdate (string as_rq, integer al_ts);//====================================================================
// 函数: gf_newdate()
//--------------------------------------------------------------------
// 描述:根据字符型日期格式和加减天数返回新的字符型日期格式
//--------------------------------------------------------------------
// 参数:日期(as_rq字符型,格式YYYYMMDD),天数(al_ts整型)
//--------------------------------------------------------------------
// 返回:  正确时返回新的日期,字符型,格式YYYYMMDD
//--------------------------------------------------------------------
// 作者:			日期: 2010年01月05日
//--------------------------------------------------------------------
//====================================================================
/*
--取当天
select CONVERT(varchar(10),GETDATE(),112)
--取昨天
select convert(varchar(10),getdate()-1,112)
*/
string ls_return
ls_return="error"
if len(as_rq)<>8 or isdate(mid(as_rq,1,4)+"-"+mid(as_rq,5,2)+"-"+mid(as_rq,7,2))=false then
	messagebox("提示","输入值不符合日期规范")
	return ls_return
end if
ls_return=string(RelativeDate(Date(mid(as_rq,1,4)+"-"+mid(as_rq,5,2)+"-"+mid(as_rq,7,2)),al_ts),"YYYYMMDD")
return ls_return
end function

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值