马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?站点注册
×
//====================================================================
// Declare: gf_dateadd.
//--------------------------------------------------------------------
// 描述:用法同sql的dateadd函数
//--------------------------------------------------------------------
// 参数:
// string as_datepart 规定应向日期的哪一部分返回新值的参数
// long al_number 增加值
// datetime adt_dt
//--------------------------------------------------------------------
// 返回: datetime
//--------------------------------------------------------------------
// 作者: YJC 日期: 2019/06/23 11:13:24
//--------------------------------------------------------------------
// CopyRight(c)
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================
Long ll_SecondTmp, ll_second, i
Int li_DaysNum
Time lt_time
Date ld_date, ld_dateTmp
String ls_Date
Constant Long DAYSECOND = 86400 //一天总共 24 * 3600 = 86400 秒
ld_date = Date(adt_dt)
lt_time = Time(adt_dt)
CHOOSE CASE as_datepart
CASE "year","yy","yyyy"
ls_Date = String(year(ld_date) + al_number) + String(ld_date, '-mm-dd')
IF NOT IsDate(ls_Date) THEN
ls_Date = String(year(ld_date) + al_number) + String(RelativeDate( ld_date, -1 ), '-mm-dd')
END IF
ld_Date = Date(ls_Date)
RETURN DateTime( ld_date, lt_time )
CASE "month","mm","m"
ld_dateTmp = Date(String(ld_date, 'yyyy-mm-') + '01')
IF al_number < 0 THEN
li_DaysNum = Integer(28+Integer(Mid('3'+String(Abs(Sign(Mod(Sign(Mod(Abs(Year(ld_dateTmp)),4))+Sign(Mod(Abs(Year(ld_dateTmp)),100))+Sign(Mod(Abs(Year(ld_dateTmp)),400)),2)) -1))+'3232332323',Month(ld_dateTmp),1)))
ld_dateTmp = Date(String(ld_dateTmp, 'yyyy-mm-') + String(li_DaysNum))
END IF
FOR i = 1 To abs(al_number)
li_DaysNum = Integer(28+Integer(Mid('3'+String(Abs(Sign(Mod(Sign(Mod(Abs(Year(ld_dateTmp)),4))+Sign(Mod(Abs(Year(ld_dateTmp)),100))+Sign(Mod(Abs(Year(ld_dateTmp)),400)),2)) -1))+'3232332323',Month(ld_dateTmp),1)))
IF al_number >= 0 THEN
ld_dateTmp = RelativeDate( ld_dateTmp, li_DaysNum )
ELSE
ld_dateTmp = RelativeDate( ld_dateTmp, 0 - li_DaysNum )
END IF
NEXT
li_DaysNum = Integer(28+Integer(Mid('3'+String(Abs(Sign(Mod(Sign(Mod(Abs(Year(ld_dateTmp)),4))+Sign(Mod(Abs(Year(ld_dateTmp)),100))+Sign(Mod(Abs(Year(ld_dateTmp)),400)),2)) -1))+'3232332323',Month(ld_dateTmp),1)))
ls_Date = String(ld_dateTmp, 'yyyy-mm-') + String(day(ld_date))
IF NOT IsDate( ls_Date ) THEN
ls_Date = String(ld_dateTmp, 'yyyy-mm-') + String(li_DaysNum)
END IF
ld_Date = Date(ls_Date)
RETURN DateTime( ld_date, lt_time )
CASE "week","wk","ww"
RETURN DateTime( RelativeDate(ld_date,al_number * 7 ), lt_time )
CASE "day","d","dd"
RETURN DateTime( RelativeDate(ld_date,al_number), lt_time )
CASE "hour","hh"
ll_SecondTmp = al_number * 3600
CASE "minute","mi","n"
ll_SecondTmp = al_number * 60
CASE "second","ss","s"
ll_SecondTmp = al_number
END CHOOSE
ll_second = Hour(lt_time) * 3600 + Minute(lt_time) * 60 + Second(lt_time)
ld_date = RelativeDate(ld_date,Integer(ll_SecondTmp/DAYSECOND))
ll_SecondTmp -= Integer(ll_SecondTmp/DAYSECOND) * DAYSECOND
If ( ll_second + ll_SecondTmp < 0 ) THEN
//RETURN DateTime(RelativeDate(ld_date,-1),RelativeTime(Time("00:00:00.000"),DAYSECOND + ll_second + ll_SecondTmp))
RETURN DateTime(RelativeDate(ld_date,-1), Time( String(RelativeTime(Time("00:00:00"), DAYSECOND + ll_second + ll_SecondTmp), 'hh:mm:ss') + '.' + String(lt_time, 'fff')))
END IF
If ( ll_second + ll_SecondTmp >= DAYSECOND ) THEN
//RETURN DateTime(RelativeDate(ld_date,1),RelativeTime(Time("00:00:00.000"),ll_second + ll_SecondTmp - DAYSECOND))
RETURN DateTime(RelativeDate(ld_date,1), Time( String(RelativeTime(Time("00:00:00"), ll_second + ll_SecondTmp - DAYSECOND), 'hh:mm:ss') + '.' + String(lt_time, 'fff')))
END IF
//RETURN DateTime( ld_date, RelativeTime( lt_time, ll_SecondTmp ) )
RETURN DateTime( ld_date, Time( String(RelativeTime( lt_time, ll_SecondTmp ), 'hh:mm:ss') + '.' + String(lt_time, 'fff')) )
|