PLwolves87
New Member
- Joined
- Jan 6, 2023
- Messages
- 31
- Office Version
- 365
- Platform
- Windows
im trying to figure out some code for amount of days between two dates, here is the code i have used and it works perfectly but now i have a problem and wondering if you could help please.
'this is the code i have and is working
Dim start_date As Date
Dim end_date As Date
Dim diff As Integer
start_date = TextBox1.Value
end_date = TextBox2.Value
diff = DateDiff("D", start_date, end_date)
TextBox3.Value = diff
example
startdate - 24/04/2023
enddate - 30/04.2023
my textbox will now show 7days which is correct
ok so the problem i have is week numbers which are shared by two months for example this year week13 (27/03/2023 - 02/04/2023) it is shared. in the above code i get the amount of days between two dates but its not looking at week number or months, what i need it to do is when the month changes it only counts those dates, so with the dates for week13 (27/03/2023 - 02/04/2023) so the amount of days returned by the DIFF should be 5days not the 7days.
hope you can help
also happy to add another textbox if it has to look like the below, so it breaks it down but this isnt important i would rather i only had one textbox for the result and just stated 5days.
textbox3 -5days
(new textbox if needed) textbox4 - 2days
thanks in advance lee
'this is the code i have and is working
Dim start_date As Date
Dim end_date As Date
Dim diff As Integer
start_date = TextBox1.Value
end_date = TextBox2.Value
diff = DateDiff("D", start_date, end_date)
TextBox3.Value = diff
example
startdate - 24/04/2023
enddate - 30/04.2023
my textbox will now show 7days which is correct
ok so the problem i have is week numbers which are shared by two months for example this year week13 (27/03/2023 - 02/04/2023) it is shared. in the above code i get the amount of days between two dates but its not looking at week number or months, what i need it to do is when the month changes it only counts those dates, so with the dates for week13 (27/03/2023 - 02/04/2023) so the amount of days returned by the DIFF should be 5days not the 7days.
hope you can help
also happy to add another textbox if it has to look like the below, so it breaks it down but this isnt important i would rather i only had one textbox for the result and just stated 5days.
textbox3 -5days
(new textbox if needed) textbox4 - 2days
thanks in advance lee