ashfaqahmedr
New Member
- Joined
- Oct 4, 2018
- Messages
- 8
Function for get Thursday as first day of week in current week month, this function returning first week as Thursday but first week of month in last month, But K need it will return only current month. For example if 1st date of month is on Tuesday it will return 1st date of month.
Function GetFirstofWeek(dtDate) As Date
'=MAX(C3-WEEKDAY(C3,14)+1, EOMONTH(C3, -1)+1)
GetFirstofWeek = DateAdd("d", dtDate, -Weekday(dtDate, vbThursday) + 1)
End Function
Function for get Wednesday as last day of week in current week month, this function returning last week as Wednesday but last week of month in next month, But I need it will return only current month. For example if last date of month is on Monday it will return 30th date of current month.
Function GetLastofWeek(dtDate As Date)
'=MIN(B2+(7-WEEKDAY(B2,14)), EOMONTH(B2, 0))
GetLastofWeek = DateAdd("d", dtDate, (7 - (Weekday(dtDate, vbWednesday)) + 1))
End Function
This function will return last date of month
Public Function EOMonth(RefDt As Date, Optional Months As Integer = 0) As Date
On Error GoTo Error_Handler
'DateSerial(Year([TxtDate]),Month([TxtDate])+1,0)
EOMonth = DateSerial(Year(RefDt), Month(RefDt) + Months + 1, 0)
End Function
This function will return first date of month
Public Function SOMonth(RefDate As Date, Optional Months As Integer = 0) As Date
On Error GoTo Error_Handler
'DateSerial(Year([TxtDate]),Month([TxtDate])-0,0)+1
SOMonth = DateSerial(Year(RefDate), Month(RefDate) + Months - 0, 0) + 1
Function GetFirstofWeek(dtDate) As Date
'=MAX(C3-WEEKDAY(C3,14)+1, EOMONTH(C3, -1)+1)
GetFirstofWeek = DateAdd("d", dtDate, -Weekday(dtDate, vbThursday) + 1)
End Function
Function for get Wednesday as last day of week in current week month, this function returning last week as Wednesday but last week of month in next month, But I need it will return only current month. For example if last date of month is on Monday it will return 30th date of current month.
Function GetLastofWeek(dtDate As Date)
'=MIN(B2+(7-WEEKDAY(B2,14)), EOMONTH(B2, 0))
GetLastofWeek = DateAdd("d", dtDate, (7 - (Weekday(dtDate, vbWednesday)) + 1))
End Function
This function will return last date of month
Public Function EOMonth(RefDt As Date, Optional Months As Integer = 0) As Date
On Error GoTo Error_Handler
'DateSerial(Year([TxtDate]),Month([TxtDate])+1,0)
EOMonth = DateSerial(Year(RefDt), Month(RefDt) + Months + 1, 0)
End Function
This function will return first date of month
Public Function SOMonth(RefDate As Date, Optional Months As Integer = 0) As Date
On Error GoTo Error_Handler
'DateSerial(Year([TxtDate]),Month([TxtDate])-0,0)+1
SOMonth = DateSerial(Year(RefDate), Month(RefDate) + Months - 0, 0) + 1