Office中國(guó)論壇/Access中國(guó)論壇

 找回密碼
 注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

返回列表 發(fā)新帖
查看: 3092|回復(fù): 5
打印 上一主題 下一主題

[模塊/函數(shù)] 【分享】常用日期公式

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2011-11-15 20:47:42 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
  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

復(fù)制代碼
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2011-11-15 21:07:57 | 只看該作者
感謝樓主的無(wú)私奉獻(xiàn)!
3#
發(fā)表于 2011-11-16 08:21:12 | 只看該作者
感謝樓主的無(wú)私奉獻(xiàn)!

點(diǎn)擊這里給我發(fā)消息

4#
發(fā)表于 2011-11-16 09:40:17 | 只看該作者
可惜沒(méi)個(gè)說(shuō)明
5#
發(fā)表于 2011-11-16 10:13:55 | 只看該作者
看不懂,能解釋下不
6#
發(fā)表于 2011-12-3 14:24:34 | 只看該作者
感謝樓主分享
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則

QQ|站長(zhǎng)郵箱|小黑屋|手機(jī)版|Office中國(guó)/Access中國(guó) ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2025-7-13 05:05 , Processed in 0.094984 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表