设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2810|回复: 5
打印 上一主题 下一主题

[模块/函数] 【分享】常用日期公式

[复制链接]
跳转到指定楼层
1#
发表于 2011-11-15 20:47:42 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
  1. Public Function FstDayOfMth(InDate As Date) As Date
  2. FstDayOfMth = DateSerial(Year(InDate), Month(InDate), 1)
  3. End Function

  4. Public Function FstDayOfNextMnth(InDate As Date) As Date
  5. FstDayOfNextMnth = DateSerial(Year(InDate), Month(InDate) + 1, 1)
  6. End Function

  7. Public Function LstDayMnth(InDate As Date) As Date
  8. LstDayMnth = DateSerial(Year(InDate), Month(InDate) + 1, 0)
  9. End Function

  10. Public Function LstDayNextMnth(InDate As Date) As Date
  11. LstDayNextMnth = DateSerial(Year(InDate), Month(InDate) + 2, 0)
  12. End Function

  13. Public Function FstDayPrevMnth(InDate As Date) As Date
  14. FstDayPrevMnth = DateSerial(Year(InDate), Month(InDate) - 1, 1)
  15. End Function

  16. Public Function LstDayPrevMnth(InDate As Date) As Date
  17. LstDayPrevMnth = DateSerial(Year(InDate), Month(InDate), 0)
  18. End Function

  19. Public Function FstDayCurQtr(InDate As Date) As Date
  20. FstDayCurQtr = DateSerial(Year(InDate), Int((Month(InDate) - 1) / 3) * 3 + 1, 1)
  21. End Function

  22. Public Function LstDayCurQtr(InDate As Date) As Date
  23. LstDayCurQtr = DateSerial(Year(InDate), Int((Month(InDate) - 1) / 3) * 3 + 4, 0)
  24. End Function

  25. Public Function FstDayCurWeek(InDate As Date) As Date
  26. FstDayCurWeek = InDate - Weekday(InDate) + 1
  27. End Function

  28. Public Function LstDayCurWeek(InDate As Date) As Date
  29. LstDayCurWeek = InDate - Weekday(InDate) + 7
  30. End Function

  31. Public Function FstDayCurWeek2(InDate As Date, InStartWeek As Integer) As Date
  32. 'The first day of the current week (using settings in Options dialog box):
  33. FstDayCurWeek2 = InDate - Weekday(InDate, InStartWeek) + 1
  34. End Function

  35. Public Function LstDayCurWeek2(InDate As Date, InStartWeek As Integer) As Date
  36. 'The last day of the current week:
  37. LstDayCurWeek2 = InDate - Weekday(InDate, 0) + 7
  38. End Function

  39. Public Function FstWeekDayOfMth(InDate As Date, DayNum As Integer) As Date
  40. Dim FirstDay As Date
  41. Dim FirstWeekDay As Integer
  42. FirstDay = DateSerial(Year(InDate), Month(InDate), 1)
  43. FirstWeekDay = Weekday(FirstDay)
  44. Select Case FirstWeekDay
  45.     Case Is < DayNum
  46.         FstWeekDayOfMth = FirstDay + DayNum - FirstWeekDay
  47.     Case Is = DayNum
  48.         FstWeekDayOfMth = FirstDay
  49.     Case Else
  50.         FstWeekDayOfMth = FirstDay + DayNum - FirstWeekDay + 7
  51. End Select

  52. End Function

复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
6#
发表于 2011-12-3 14:24:34 | 只看该作者
感谢楼主分享
5#
发表于 2011-11-16 10:13:55 | 只看该作者
看不懂,能解释下不

点击这里给我发消息

4#
发表于 2011-11-16 09:40:17 | 只看该作者
可惜没个说明
3#
发表于 2011-11-16 08:21:12 | 只看该作者
感谢楼主的无私奉献!
2#
发表于 2011-11-15 21:07:57 | 只看该作者
感谢楼主的无私奉献!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-12-1 19:49 , Processed in 0.103756 second(s), 30 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表