fisrt and last day of month and week

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,
 
J

John W. Vinson

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
 
S

Souris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top