首页 > 代码库 > PowerBuilder -- 日期

PowerBuilder -- 日期

 

#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

#根据日期获取当月的天数

//====================================================================
// 事件: u_sysfunc.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

 

PowerBuilder -- 日期