Calculate Number of Working Days without Holidays & Weekends [duplicate]












1















This question is an exact duplicate of:




  • Why is datediff interval “weekday” returning interval based on weeks and not days minus weekends?

    1 answer




How can I calculate the number of working days between two dates without counting Saturdays, Sundays and holidays.



I have a table with the following fields:
enter image description here



I have the following table and what I want is that in the column called expr1 calculate the difference of working days.



Enter the code into Visual Basic, and call workingdays to the module



enter image description here



Replace the variables with the names of each column.



Function WorkingDays(ByVal FECHA_DE_VALIDACION_FA As Date, ByVal FECHA_IMPRESIÓN As Date) As Long
While FECHA_DE_VALIDACION_FA <= FECHA_IMPRESIÓN
Select Case True
Case Weekday(FECHA_DE_VALIDACION_FA, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
FECHA_DE_VALIDACION_FA = FECHA_DE_VALIDACION_FA + 1
Wend
End Function


Then they tell me that in the query with the generator call the function Workingdays, but it does not give me a result.



enter image description here
enter image description here



I accept and run the query but I get an error.










share|improve this question















marked as duplicate by Gustav ms-access
Users with the  ms-access badge can single-handedly close ms-access questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:57


This question was marked as an exact duplicate of an existing question.















  • Save holidays in a separate table, enter those days manually, that will be mach easier than calculate on the fly.
    – Tony Dong
    Nov 20 at 20:07










  • docs.microsoft.com/en-us/previous-versions/office/developer/…. Not based on your code but does exactly what you're looking for. Tested in Access 2013 and works for me.
    – Barbara
    Nov 22 at 22:53
















1















This question is an exact duplicate of:




  • Why is datediff interval “weekday” returning interval based on weeks and not days minus weekends?

    1 answer




How can I calculate the number of working days between two dates without counting Saturdays, Sundays and holidays.



I have a table with the following fields:
enter image description here



I have the following table and what I want is that in the column called expr1 calculate the difference of working days.



Enter the code into Visual Basic, and call workingdays to the module



enter image description here



Replace the variables with the names of each column.



Function WorkingDays(ByVal FECHA_DE_VALIDACION_FA As Date, ByVal FECHA_IMPRESIÓN As Date) As Long
While FECHA_DE_VALIDACION_FA <= FECHA_IMPRESIÓN
Select Case True
Case Weekday(FECHA_DE_VALIDACION_FA, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
FECHA_DE_VALIDACION_FA = FECHA_DE_VALIDACION_FA + 1
Wend
End Function


Then they tell me that in the query with the generator call the function Workingdays, but it does not give me a result.



enter image description here
enter image description here



I accept and run the query but I get an error.










share|improve this question















marked as duplicate by Gustav ms-access
Users with the  ms-access badge can single-handedly close ms-access questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:57


This question was marked as an exact duplicate of an existing question.















  • Save holidays in a separate table, enter those days manually, that will be mach easier than calculate on the fly.
    – Tony Dong
    Nov 20 at 20:07










  • docs.microsoft.com/en-us/previous-versions/office/developer/…. Not based on your code but does exactly what you're looking for. Tested in Access 2013 and works for me.
    – Barbara
    Nov 22 at 22:53














1












1








1








This question is an exact duplicate of:




  • Why is datediff interval “weekday” returning interval based on weeks and not days minus weekends?

    1 answer




How can I calculate the number of working days between two dates without counting Saturdays, Sundays and holidays.



I have a table with the following fields:
enter image description here



I have the following table and what I want is that in the column called expr1 calculate the difference of working days.



Enter the code into Visual Basic, and call workingdays to the module



enter image description here



Replace the variables with the names of each column.



Function WorkingDays(ByVal FECHA_DE_VALIDACION_FA As Date, ByVal FECHA_IMPRESIÓN As Date) As Long
While FECHA_DE_VALIDACION_FA <= FECHA_IMPRESIÓN
Select Case True
Case Weekday(FECHA_DE_VALIDACION_FA, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
FECHA_DE_VALIDACION_FA = FECHA_DE_VALIDACION_FA + 1
Wend
End Function


Then they tell me that in the query with the generator call the function Workingdays, but it does not give me a result.



enter image description here
enter image description here



I accept and run the query but I get an error.










share|improve this question
















This question is an exact duplicate of:




  • Why is datediff interval “weekday” returning interval based on weeks and not days minus weekends?

    1 answer




How can I calculate the number of working days between two dates without counting Saturdays, Sundays and holidays.



I have a table with the following fields:
enter image description here



I have the following table and what I want is that in the column called expr1 calculate the difference of working days.



Enter the code into Visual Basic, and call workingdays to the module



enter image description here



Replace the variables with the names of each column.



Function WorkingDays(ByVal FECHA_DE_VALIDACION_FA As Date, ByVal FECHA_IMPRESIÓN As Date) As Long
While FECHA_DE_VALIDACION_FA <= FECHA_IMPRESIÓN
Select Case True
Case Weekday(FECHA_DE_VALIDACION_FA, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
FECHA_DE_VALIDACION_FA = FECHA_DE_VALIDACION_FA + 1
Wend
End Function


Then they tell me that in the query with the generator call the function Workingdays, but it does not give me a result.



enter image description here
enter image description here



I accept and run the query but I get an error.





This question is an exact duplicate of:




  • Why is datediff interval “weekday” returning interval based on weeks and not days minus weekends?

    1 answer








ms-access access-vba ms-access-2007






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 7:43









Nick

22.8k81535




22.8k81535










asked Nov 20 at 20:04









Lina Marcela Hernández Diaz

83




83




marked as duplicate by Gustav ms-access
Users with the  ms-access badge can single-handedly close ms-access questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:57


This question was marked as an exact duplicate of an existing question.






marked as duplicate by Gustav ms-access
Users with the  ms-access badge can single-handedly close ms-access questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:57


This question was marked as an exact duplicate of an existing question.














  • Save holidays in a separate table, enter those days manually, that will be mach easier than calculate on the fly.
    – Tony Dong
    Nov 20 at 20:07










  • docs.microsoft.com/en-us/previous-versions/office/developer/…. Not based on your code but does exactly what you're looking for. Tested in Access 2013 and works for me.
    – Barbara
    Nov 22 at 22:53


















  • Save holidays in a separate table, enter those days manually, that will be mach easier than calculate on the fly.
    – Tony Dong
    Nov 20 at 20:07










  • docs.microsoft.com/en-us/previous-versions/office/developer/…. Not based on your code but does exactly what you're looking for. Tested in Access 2013 and works for me.
    – Barbara
    Nov 22 at 22:53
















Save holidays in a separate table, enter those days manually, that will be mach easier than calculate on the fly.
– Tony Dong
Nov 20 at 20:07




Save holidays in a separate table, enter those days manually, that will be mach easier than calculate on the fly.
– Tony Dong
Nov 20 at 20:07












docs.microsoft.com/en-us/previous-versions/office/developer/…. Not based on your code but does exactly what you're looking for. Tested in Access 2013 and works for me.
– Barbara
Nov 22 at 22:53




docs.microsoft.com/en-us/previous-versions/office/developer/…. Not based on your code but does exactly what you're looking for. Tested in Access 2013 and works for me.
– Barbara
Nov 22 at 22:53












1 Answer
1






active

oldest

votes


















0














As Tony suggests in the comments, you will first need to construct a table containing dates of holidays, as these can vary from year-to-year.



Then, rather than using functions such as DateDiff, the easiest method is probably to incrementally count the number of days between the two dates, without incrementing the counter should the date be a Saturday or Sunday, or a member of your holidays table, e.g.:



Function WorkingDays(ByVal fromDate As Date, ByVal toDate As Date) As Long
While fromDate <= toDate
Select Case True
Case Weekday(fromDate, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
fromDate = fromDate + 1
Wend
End Function


The above assumes that you have a table called Holidays containing a field called Holiday with all of the holiday dates to be excluded.



The above function counts the number of working days inclusive of the two supplied dates.



For example, assuming that your Holidays table contains the following dates:



Holidays



Then the function would return the following:



?WorkingDays(#2018-12-24#, #2019-01-04#)
7


To use the code, open the VBA IDE (Alt+F11), insert a new Module (Alt, I, M) and then paste the code into the module and save the module.



You can then call the function from anywhere where the Expression Builder is available.






share|improve this answer























  • Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:11










  • How can I put the imagen the acces? for you can see
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:16










  • @LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
    – Lee Mac
    Nov 22 at 13:27










  • Lee Mac, I added the example in the description of what I did but it does not run.
    – Lina Marcela Hernández Diaz
    Nov 22 at 16:02










  • @LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
    – Lee Mac
    Nov 22 at 17:20




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As Tony suggests in the comments, you will first need to construct a table containing dates of holidays, as these can vary from year-to-year.



Then, rather than using functions such as DateDiff, the easiest method is probably to incrementally count the number of days between the two dates, without incrementing the counter should the date be a Saturday or Sunday, or a member of your holidays table, e.g.:



Function WorkingDays(ByVal fromDate As Date, ByVal toDate As Date) As Long
While fromDate <= toDate
Select Case True
Case Weekday(fromDate, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
fromDate = fromDate + 1
Wend
End Function


The above assumes that you have a table called Holidays containing a field called Holiday with all of the holiday dates to be excluded.



The above function counts the number of working days inclusive of the two supplied dates.



For example, assuming that your Holidays table contains the following dates:



Holidays



Then the function would return the following:



?WorkingDays(#2018-12-24#, #2019-01-04#)
7


To use the code, open the VBA IDE (Alt+F11), insert a new Module (Alt, I, M) and then paste the code into the module and save the module.



You can then call the function from anywhere where the Expression Builder is available.






share|improve this answer























  • Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:11










  • How can I put the imagen the acces? for you can see
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:16










  • @LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
    – Lee Mac
    Nov 22 at 13:27










  • Lee Mac, I added the example in the description of what I did but it does not run.
    – Lina Marcela Hernández Diaz
    Nov 22 at 16:02










  • @LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
    – Lee Mac
    Nov 22 at 17:20


















0














As Tony suggests in the comments, you will first need to construct a table containing dates of holidays, as these can vary from year-to-year.



Then, rather than using functions such as DateDiff, the easiest method is probably to incrementally count the number of days between the two dates, without incrementing the counter should the date be a Saturday or Sunday, or a member of your holidays table, e.g.:



Function WorkingDays(ByVal fromDate As Date, ByVal toDate As Date) As Long
While fromDate <= toDate
Select Case True
Case Weekday(fromDate, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
fromDate = fromDate + 1
Wend
End Function


The above assumes that you have a table called Holidays containing a field called Holiday with all of the holiday dates to be excluded.



The above function counts the number of working days inclusive of the two supplied dates.



For example, assuming that your Holidays table contains the following dates:



Holidays



Then the function would return the following:



?WorkingDays(#2018-12-24#, #2019-01-04#)
7


To use the code, open the VBA IDE (Alt+F11), insert a new Module (Alt, I, M) and then paste the code into the module and save the module.



You can then call the function from anywhere where the Expression Builder is available.






share|improve this answer























  • Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:11










  • How can I put the imagen the acces? for you can see
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:16










  • @LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
    – Lee Mac
    Nov 22 at 13:27










  • Lee Mac, I added the example in the description of what I did but it does not run.
    – Lina Marcela Hernández Diaz
    Nov 22 at 16:02










  • @LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
    – Lee Mac
    Nov 22 at 17:20
















0












0








0






As Tony suggests in the comments, you will first need to construct a table containing dates of holidays, as these can vary from year-to-year.



Then, rather than using functions such as DateDiff, the easiest method is probably to incrementally count the number of days between the two dates, without incrementing the counter should the date be a Saturday or Sunday, or a member of your holidays table, e.g.:



Function WorkingDays(ByVal fromDate As Date, ByVal toDate As Date) As Long
While fromDate <= toDate
Select Case True
Case Weekday(fromDate, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
fromDate = fromDate + 1
Wend
End Function


The above assumes that you have a table called Holidays containing a field called Holiday with all of the holiday dates to be excluded.



The above function counts the number of working days inclusive of the two supplied dates.



For example, assuming that your Holidays table contains the following dates:



Holidays



Then the function would return the following:



?WorkingDays(#2018-12-24#, #2019-01-04#)
7


To use the code, open the VBA IDE (Alt+F11), insert a new Module (Alt, I, M) and then paste the code into the module and save the module.



You can then call the function from anywhere where the Expression Builder is available.






share|improve this answer














As Tony suggests in the comments, you will first need to construct a table containing dates of holidays, as these can vary from year-to-year.



Then, rather than using functions such as DateDiff, the easiest method is probably to incrementally count the number of days between the two dates, without incrementing the counter should the date be a Saturday or Sunday, or a member of your holidays table, e.g.:



Function WorkingDays(ByVal fromDate As Date, ByVal toDate As Date) As Long
While fromDate <= toDate
Select Case True
Case Weekday(fromDate, vbMonday) > 5
Case DCount("*", "Holidays", "Holiday = #" & Format(fromDate, "mm/dd/yyyy") & "#") > 0
Case Else: WorkingDays = WorkingDays + 1
End Select
fromDate = fromDate + 1
Wend
End Function


The above assumes that you have a table called Holidays containing a field called Holiday with all of the holiday dates to be excluded.



The above function counts the number of working days inclusive of the two supplied dates.



For example, assuming that your Holidays table contains the following dates:



Holidays



Then the function would return the following:



?WorkingDays(#2018-12-24#, #2019-01-04#)
7


To use the code, open the VBA IDE (Alt+F11), insert a new Module (Alt, I, M) and then paste the code into the module and save the module.



You can then call the function from anywhere where the Expression Builder is available.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 at 13:26

























answered Nov 20 at 20:57









Lee Mac

3,30731338




3,30731338












  • Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:11










  • How can I put the imagen the acces? for you can see
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:16










  • @LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
    – Lee Mac
    Nov 22 at 13:27










  • Lee Mac, I added the example in the description of what I did but it does not run.
    – Lina Marcela Hernández Diaz
    Nov 22 at 16:02










  • @LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
    – Lee Mac
    Nov 22 at 17:20




















  • Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:11










  • How can I put the imagen the acces? for you can see
    – Lina Marcela Hernández Diaz
    Nov 22 at 13:16










  • @LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
    – Lee Mac
    Nov 22 at 13:27










  • Lee Mac, I added the example in the description of what I did but it does not run.
    – Lina Marcela Hernández Diaz
    Nov 22 at 16:02










  • @LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
    – Lee Mac
    Nov 22 at 17:20


















Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
– Lina Marcela Hernández Diaz
Nov 22 at 13:11




Hello, thanks for your answer, I have a question: Where I put this code. I have a two columns and I want a third one called validation to show me the working day.
– Lina Marcela Hernández Diaz
Nov 22 at 13:11












How can I put the imagen the acces? for you can see
– Lina Marcela Hernández Diaz
Nov 22 at 13:16




How can I put the imagen the acces? for you can see
– Lina Marcela Hernández Diaz
Nov 22 at 13:16












@LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
– Lee Mac
Nov 22 at 13:27




@LinaMarcelaHernándezDiaz I have updated my answer with more information about how the code can be used. Unfortunately your question has been marked as a duplicate and so you are limited in what you can do to change it.
– Lee Mac
Nov 22 at 13:27












Lee Mac, I added the example in the description of what I did but it does not run.
– Lina Marcela Hernández Diaz
Nov 22 at 16:02




Lee Mac, I added the example in the description of what I did but it does not run.
– Lina Marcela Hernández Diaz
Nov 22 at 16:02












@LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
– Lee Mac
Nov 22 at 17:20






@LinaMarcelaHernándezDiaz The example included in my answer was run from within the VBA IDE Immediate Window, which you can access by pressing Ctrl+G whilst in the VBA IDE. To display a result in a textbox, for example, you might set the Control Source to =WorkingDays([YourDateField1], [YourDateField2])
– Lee Mac
Nov 22 at 17:20





Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen