#PB自带日期相关函数
Date(...), DateTime(...), RelativeDate(...), Year(...), Month(...), Day(...), DaysAfter(...)
#根据日期获取间隔n月第一天
//==================================================================== // 事件: uf_get_first_day() //-------------------------------------------------------------------- // 描述: 根据日期获取间隔n月第一天 //-------------------------------------------------------------------- // 参数: // value date ad_date // value integer ai_n //-------------------------------------------------------------------- // 返回: date //==================================================================== Date ld_first_day Int li_year, li_month li_year = Year(ad_date) li_month = Month(ad_date) li_month = li_month + ai_n Do While li_month < 0 li_month = li_month + 12 li_year = li_year - 1 Loop Do While li_month > 12 li_month = li_month - 12 li_year = li_year + 1 Loop ld_first_day = Date(String(li_year) + '-' + String(li_month) + '-1') Return ld_first_day
#根据日期获取当月最后一天的日期
//==================================================================== // 事件: uf_get_last_day() //-------------------------------------------------------------------- // 描述: 根据日期获取当月最后一天的日期 //-------------------------------------------------------------------- // 参数: // value date ad_date //-------------------------------------------------------------------- // 返回: date //==================================================================== Date ld_last_day Int li_year, li_month, li_day li_year = Year(ad_date) li_month = Month(ad_date) li_day = uf_get_daynum(ad_date) ld_last_day = Date(String(li_year) + '-' + String(li_month) + '-' + String(li_day)) Return ld_last_day
#根据日期获取当月的天数
//==================================================================== // 事件: uf_get_daynum() //-------------------------------------------------------------------- // 描述: 根据日期获取当月的天数 //-------------------------------------------------------------------- // 参数: // value date ad_date //-------------------------------------------------------------------- // 返回: integer //==================================================================== Int li_year, li_month, li_daynum li_year = Year(ad_date) li_month = Month(ad_date) Choose Case li_month Case 1, 3, 5, 7, 8, 10, 12 li_daynum = 31 Case 4, 6, 9, 11 li_daynum = 30 Case 2 If (Mod(li_year, 4) = 0 And Mod(li_year, 100) <> 0) Or Mod(li_year, 400) = 0 Then li_daynum = 29 Else li_daynum = 28 End If End Choose Return li_daynum
#计算两个带时间部分的日期的间隔 秒
原文:https://bbs.csdn.net/topics/392383457 二楼
//==================================================================== // 事件: wf_time_interval() //-------------------------------------------------------------------- // 描述: 计算两个带时间部分的日期的间隔 秒 //-------------------------------------------------------------------- // 参数: // datetime adt_begin // datetime adt_end //-------------------------------------------------------------------- // 返回: long //==================================================================== DateTime ldt_begin, ldt_end Long ll_day, ll_seconds, ll_value, ll_ret If adt_begin > adt_end Then ldt_begin = adt_end ldt_end = adt_begin ll_ret = -1 Else ldt_begin = adt_begin ldt_end = adt_end ll_ret = 1 End If ll_day = DaysAfter(Date(ldt_begin), Date(ldt_end)) - 1 ll_seconds = SecondsAfter(Time(ldt_begin), 23:59:59) + 1 ll_seconds += SecondsAfter(00:00:00, Time(ldt_end)) ll_value = ll_day * 24 * 3600 + ll_seconds ll_ret = ll_ret * ll_value Return ll_ret