I want an integer in return which expresses the number of days between two dates. Ex: First date: Sept 30, 2013 Second date:October 2, 2013 - will return "3".
Hope to get some help with this!
Roar, Norway
I want an integer in return which expresses the number of days between two dates. Ex: First date: Sept 30, 2013 Second date:October 2, 2013 - will return "3".
Hope to get some help with this!
Roar, Norway
Investigate DateDiff function. Access Help has guidelines.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Thank you - for putting me on the right trace - I made this formula: =(DateDiff("d";[FromDt];[ToDt])+1)
But I don't want all the days included - only the work days, e.g.: Mon Tue Wed Thu Fri - and not Sat and Sun. I discovered an intverval code "w" for the six weekdays, but didn't find any code for work days. Can I still use this DateDiff function or do I have to use another function?
That will require your own User Defined Function (UDF). Here's what I use if there is no Holiday table:
Code:Public Function NetWorkdays(dteStart As Date, dteEnd As Date) As Integer '-- Returns a negative number if dteStart is > dteEnd Dim intGrossDays As Integer Dim dteCurrDate As Date Dim i As Integer intGrossDays = Abs(DateDiff("d", dteStart, dteEnd)) NetWorkdays = 0 For i = 0 To intGrossDays dteCurrDate = dteStart + i If Weekday(dteCurrDate, vbMonday) < 6 Then NetWorkdays = NetWorkdays + 1 End If Next i If dteStart > dteEnd Then NetWorkdays = NetWorkdays * -1 End If End Function
BTW, UDF's need to be in a Standard Module and not in a Form's module.
As RG noted, that code won't handle holidays. If you need to consider holidays, will need a table of holidays and modify code. This is common topic in forum and many code examples on web.
Put function in standard module if want to be able to access it from multiple locations, otherwise UDF's can be placed behind forms and reports. They just would be available only to the form or report they are behind.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.