jkoneil
asked on
Difference between 2 dates in Months, Days, Hours, Minutes
Hi everyone. I have looked through previously answered questions but I can't find a solution for what I need to accomplish and I am hoping that someone can help.
I am trying to create metrics reports that contain the date that a request was entered, the date that the request was completed and the difference between the 2 dates with the results in Months, Days, Hours, Minutes format. The difference needs to be displayed in one column and in another column I need the difference between the 2 dates - not including weekends and holidays. For example: if a request is submitted on Friday morning at 4:30pm and completed on Monday at 10am, I do not want the difference in the second column to show as 2 + days.
Is this possible?
Thanks,
Josette
I am trying to create metrics reports that contain the date that a request was entered, the date that the request was completed and the difference between the 2 dates with the results in Months, Days, Hours, Minutes format. The difference needs to be displayed in one column and in another column I need the difference between the 2 dates - not including weekends and holidays. For example: if a request is submitted on Friday morning at 4:30pm and completed on Monday at 10am, I do not want the difference in the second column to show as 2 + days.
Is this possible?
Thanks,
Josette
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I wanna change the above code a bit
count=0
for i = convert_to_integer(startdate) to convert_to_integer(enddate)
if day_of_week(convert_to_date(i)) is NOT weekend
count++;
end if
next
Using Months in such a measurement is totally meaningless, especially when you are excludiing weekends and holidays.
Stick to days.
Stick to days.
ASKER
How do I get the Interval referenced in the function?
Is it just Datediff(DateCompleted-Dat eRequested )?
Thanks.
Josette
Is it just Datediff(DateCompleted-Dat
Thanks.
Josette
if you will refer to the link..
it should be
ElapsedTime(#6/1/1999 8:23:00PM#-#6/1/1999 8:12:12AM#)
it should be
ElapsedTime(#6/1/1999 8:23:00PM#-#6/1/1999 8:12:12AM#)
ASKER
Is there a way for me to split this question so that I can award points individually? I was able to get the first part working using the function from capricorn1 but I am still working on calculating without the weekends.
Thanks,
Josette
Thanks,
Josette
just add this test
if DateDiff("ww", DateSerial(Year(dateReques t), Month(dateRequest), 1), dateRequest, vbSunday) + 1 = DateDiff("ww", DateSerial(Year(dateComple ted), Month(dateCompleted), 1), dateCompleted, vbSunday) + 1 then
' do nothing same week
else
'subract two days or 48 hours
end if
if DateDiff("ww", DateSerial(Year(dateReques
' do nothing same week
else
'subract two days or 48 hours
end if
ASKER
Since I need a column for the amount of time including the weekend and a column for the amount of time not including the weekend, I added a new function with the following:
else
ElapsedTimeNoWeekend = DateAdd("d", -2, x)
This did not work. I receive a # error when I run the query using this function.
Also, does the check assume that there can only be one weekend between the request and the completion? We have several cases where there are weeks between the request and the completion.
Thanks for your help.
Josette
else
ElapsedTimeNoWeekend = DateAdd("d", -2, x)
This did not work. I receive a # error when I run the query using this function.
Also, does the check assume that there can only be one weekend between the request and the completion? We have several cases where there are weeks between the request and the completion.
Thanks for your help.
Josette
{ We have several cases where there are weeks between the request and the completion. }
now, a user define function is what you need, please post all the possible scenarios
now, a user define function is what you need, please post all the possible scenarios
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the function Gustav. I was able to use it to determine the minutes. I haven't been able to convert the minutes to days, hours and minutes yet.
Can I repost the Working Days portion of the questions so that I can award full points for you and capricorn1 for the ElapsedTime function?
Can I repost the Working Days portion of the questions so that I can award full points for you and capricorn1 for the ElapsedTime function?
Thanks, but a split is fine with me.
You can extract the day, hour, and minute count by using Modulus and integer division:
intMinutes = lngMinutes Mod 60
intHours = lngMinutes \ 60 Mod 24
intDays = lngMinutes \ 60 \ 24
/gustav
You can extract the day, hour, and minute count by using Modulus and integer division:
intMinutes = lngMinutes Mod 60
intHours = lngMinutes \ 60 Mod 24
intDays = lngMinutes \ 60 \ 24
/gustav
ASKER
Thank you for all of your help. The metrics queries seem to be running fine.
You are welcome!
/gustav
/gustav
Open in new window