Office中国论坛/Access中国论坛
标题:
【分享】常用日期公式
[打印本页]
作者:
andymark
时间:
2011-11-15 20:47
标题:
【分享】常用日期公式
Public Function FstDayOfMth(InDate As Date) As Date
FstDayOfMth = DateSerial(Year(InDate), Month(InDate), 1)
End Function
Public Function FstDayOfNextMnth(InDate As Date) As Date
FstDayOfNextMnth = DateSerial(Year(InDate), Month(InDate) + 1, 1)
End Function
Public Function LstDayMnth(InDate As Date) As Date
LstDayMnth = DateSerial(Year(InDate), Month(InDate) + 1, 0)
End Function
Public Function LstDayNextMnth(InDate As Date) As Date
LstDayNextMnth = DateSerial(Year(InDate), Month(InDate) + 2, 0)
End Function
Public Function FstDayPrevMnth(InDate As Date) As Date
FstDayPrevMnth = DateSerial(Year(InDate), Month(InDate) - 1, 1)
End Function
Public Function LstDayPrevMnth(InDate As Date) As Date
LstDayPrevMnth = DateSerial(Year(InDate), Month(InDate), 0)
End Function
Public Function FstDayCurQtr(InDate As Date) As Date
FstDayCurQtr = DateSerial(Year(InDate), Int((Month(InDate) - 1) / 3) * 3 + 1, 1)
End Function
Public Function LstDayCurQtr(InDate As Date) As Date
LstDayCurQtr = DateSerial(Year(InDate), Int((Month(InDate) - 1) / 3) * 3 + 4, 0)
End Function
Public Function FstDayCurWeek(InDate As Date) As Date
FstDayCurWeek = InDate - Weekday(InDate) + 1
End Function
Public Function LstDayCurWeek(InDate As Date) As Date
LstDayCurWeek = InDate - Weekday(InDate) + 7
End Function
Public Function FstDayCurWeek2(InDate As Date, InStartWeek As Integer) As Date
'The first day of the current week (using settings in Options dialog box):
FstDayCurWeek2 = InDate - Weekday(InDate, InStartWeek) + 1
End Function
Public Function LstDayCurWeek2(InDate As Date, InStartWeek As Integer) As Date
'The last day of the current week:
LstDayCurWeek2 = InDate - Weekday(InDate, 0) + 7
End Function
Public Function FstWeekDayOfMth(InDate As Date, DayNum As Integer) As Date
Dim FirstDay As Date
Dim FirstWeekDay As Integer
FirstDay = DateSerial(Year(InDate), Month(InDate), 1)
FirstWeekDay = Weekday(FirstDay)
Select Case FirstWeekDay
Case Is < DayNum
FstWeekDayOfMth = FirstDay + DayNum - FirstWeekDay
Case Is = DayNum
FstWeekDayOfMth = FirstDay
Case Else
FstWeekDayOfMth = FirstDay + DayNum - FirstWeekDay + 7
End Select
End Function
复制代码
作者:
ly
时间:
2011-11-15 21:07
感谢楼主的无私奉献!
作者:
yanwei82123300
时间:
2011-11-16 08:21
感谢楼主的无私奉献!
作者:
轻风
时间:
2011-11-16 09:40
可惜没个说明
作者:
jinzhanxi
时间:
2011-11-16 10:13
看不懂,能解释下不
作者:
changweiren
时间:
2011-12-3 14:24
感谢楼主分享
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3