|
DateTime: Diverses manipulations sur des dates |
Author(s) Lewis Moseley |
|
---Soumis par Lewis Moseley---
Diverses manipulations sur des dates.
Voici quelques manipulations simples sur des dates qui
permette de retourner des dates dans le passé ou le futur.
Noter qu'on peut combiner ces fonctions, comme pour
trouver le dernier jour du prochain mois:
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
|