Clear
ldDate=Date()
ldDateB={^2004/02/29}
ldDateE={^2005/02/28}
*--月天数
?"月天数",32-Day(ldDate-Day(ldDate)+32)
*--月初日期
?"月初日期",ldDate-Day(ldDate)+1
?"月初日期",Date(Year(ldDate),Month(ldDate),1)
*--月末日期
?"月末日期",Gomonth(ldDate-Day(ldDate)+1,1)-1
?"月末日期",Gomonth(ldDate,1)-Day(Gomonth(ldDate,1))
?"月末日期",ldDate-Day(ldDate)+32-Day(ldDate-Day(ldDate)+32)
?"月末日期",Date(Year(Gomonth(ldDate,1)),Month(Gomonth(ldDate,1)),1)-1
*--两个日期之间天数(Max是防止ldDateE小于ldDateB)
?"两个日期之间天数",Max(ldDateE-ldDateB,0)
*--两个日期之间月数(Max是防止ldDateE小于ldDateB)
?"两个日期之间月数",Max((Year(ldDateE)-Year(ldDateB))*12+Month(ldDateE)-(Month(ldDateB)+Iif((Day(ldDateE)<Day(ldDateB) And Day(ldDateE+1)>1),1,0)),0)
*--两个日期之间年数,可以用于计算年龄(Max是防止ldDateE小于ldDateB)
?"两个日期之间年数",Max(Year(ldDateE)-Year(ldDateB)-Iif(Gomonth(ldDateB,(Year(ldDateE)-Year(ldDateB))*12)>ldDateE,1,0),0)
?"两个日期之间年数",Max(Int(((Year(ldDateE)-Year(ldDateB))*12+Month(ldDateE)-(Month(ldDateB)+Iif((Day(ldDateE)<Day(ldDateB) And Day(ldDateE+1)>1),1,0)))/12),0)