Here are some simple date manipulation functions that can be used to
return a specific date in the future/past.
Note that you can combine these functions to, for example, find the
lastday of next month:
newdate = LastOfMonth( NextMonth( olddate )
)
Function FirstOfMonth(InputDate As Date)
Dim D As Integer, M As Integer, Y As Integer
If IsNull(InputDate) Then
FirstOfMonth = Null
Else
D = Day(InputDate)
M = Month(InputDate)
Y = Year(InputDate)
FirstOfMonth = DateSerial(Y, M, 1)
End If
End Function
Function LastOfMonth(InputDate As Date)
Dim D As Integer, M As Integer, Y As Integer
If IsNull(InputDate) Then
LastOfMonth = Null
Else
D = Day(InputDate)
M = Month(InputDate)
Y = Year(InputDate)
LastOfMonth = DateAdd("m", 1, DateSerial(Y, M, 1)) - 1
End If
End Function
Function NextMonth(InputDate As Date)
NextMonth = DateAdd("m", 1, InputDate)
End Function
Function LastMonth(InputDate As Date)
LastMonth = DateAdd("m", -1, InputDate)
End Function
Function SetDayOfMonth(InputDate As Date, DayToSet As Integer)
Dim M As Integer, Y As Integer
If IsNull(InputDate) Then
SetDayOfMonth = Null
Else
M = Month(InputDate)
Y = Year(InputDate)
SetDayOfMonth = DateSerial(Y, M, DayToSet)
End If
End Function
|