fisrt and last day of month and week

  • Thread starter Thread starter Souris
  • Start date Start date
S

Souris

Are there any functions to return the first and last day of week and month?

I am looking for a function to pass now and get the first and last date of
week and month.

Does it exist?

Your information is great appreciated,
 
Are there any functions to return the first and last day of week and month?

I am looking for a function to pass now and get the first and last date of
week and month.

Does it exist?

Your information is great appreciated,

Not builtin, but all four are easy to create using the builtin date functions.
Try these:

Public Function FirstDayOfMonth() As Date
FirstDayOfMonth = DateSerial(Year(Date), Month(Date), 1)
End Function
Public Function LastDayOfMonth() As Date
LastDayOfMonth = DateSerial(Year(Date), Month(Date)+1, 0)
End Function
Public Function FirstDayOfWeek() As Date
' assuming you mean Monday as the first day of the week
FirstDayOfWeek = DateAdd("d", 1 - Weekday(Date), Date)
End Function
Public Function LarstDayOfWeek() As Date
' assuming you mean Friday as the last day of the week
LastDayOfWeek = DateAdd("d", 6 - Weekday(Date), Date)
End Function
 
Thanks millions,



John W. Vinson said:
Not builtin, but all four are easy to create using the builtin date functions.
Try these:

Public Function FirstDayOfMonth() As Date
FirstDayOfMonth = DateSerial(Year(Date), Month(Date), 1)
End Function
Public Function LastDayOfMonth() As Date
LastDayOfMonth = DateSerial(Year(Date), Month(Date)+1, 0)
End Function
Public Function FirstDayOfWeek() As Date
' assuming you mean Monday as the first day of the week
FirstDayOfWeek = DateAdd("d", 1 - Weekday(Date), Date)
End Function
Public Function LarstDayOfWeek() As Date
' assuming you mean Friday as the last day of the week
LastDayOfWeek = DateAdd("d", 6 - Weekday(Date), Date)
End Function
 
Back
Top