forked from farishadi/Excel_Macro_References
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetFirstLastDateInQtr
More file actions
27 lines (18 loc) · 814 Bytes
/
GetFirstLastDateInQtr
File metadata and controls
27 lines (18 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Public Function LastDateInQtr(Optional checkDate As Date = 0) As Date
'Function returns the last day in the quarter based on date
Const numOfMnthsInQtr As Integer = 3
If checkDate = 0 Then
'use current date if no date passed in
checkDate = Date
End If
LastDateInQtr = DateSerial(Year(checkDate), Int((Month(checkDate) - 1) / numOfMnthsInQtr) * numOfMnthsInQtr + (numOfMnthsInQtr + 1), 0)
End Function
Public Function FirstDateInQtr(Optional checkDate As Date = 0) As Date
'Function returns the first day in the quarter based on date
Const numOfMnthsInQtr As Integer = 3
If checkDate = 0 Then
'use current date if no date passed in
checkDate = Date
End If
FirstDateInQtr = DateSerial(Year(checkDate), Int((Month(checkDate) - 1) / numOfMnthsInQtr) * numOfMnthsInQtr + 1, 1)
End Function