Date Function in Access

dhen21dx

Board Regular
Joined
May 10, 2013
Messages
166
Hi Guys,

I need help on calculation of Time in Access. I have a Received Date and Closed Date, i do need to check if the time of Received date is =< 8:00 AM till 4:00 PM, if it is then i need to check if the time of Closing Date is at 5:00 PM (means same day closing) remarks will be Pass, Failed for those closing time 5:01 onwards. For the second validation, if received date time is 4:01 PM onwards, then 24 hours apply and remaks as Pass, if more than 24 hours mark as Failed.

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is this still an issue?
If so, are your dates "complete" dates, with date/time values combined. E.g. "1/31/2016 10:15 AM" and so on? Best case, provide some examples of your data and a few passes and fails.
 
Upvote 0
Hi Xenou,

Here is the example with few pass and fails, hopefully you can help me with this one.
Thanks


Request QueueReceived DateFixed DateResultRemarks *exclude Sat and Sun
Req16/27/16 3:21 PM6/27/16 3:36 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req26/30/16 12:52 PM6/30/16 3:23 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req36/30/16 6:58 PM6/30/16 7:01 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req46/27/16 12:01 PM6/27/16 12:16 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req56/10/16 12:55 PM6/10/16 3:30 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req66/1/16 1:45 PM6/1/16 3:42 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req76/9/16 4:53 PM6/16/16 8:44 AMFailReceived After 4:00 PM and closed >24 hours
Req85/30/16 3:59 PM6/6/16 11:37 PMFailReceived Between <=8:00 AM to 4:00 PM but closed >5:00 PM
Req96/14/16 3:59 PM6/14/16 7:36 PMFailReceived Between <=8:00 AM to 4:00 PM but closed >5:00 PM
Req106/20/16 12:50 PM6/20/16 2:06 PMPassReceived Between <=8:00 AM to 4:00 PM and closed =<5:00 PM
Req116/16/16 4:49 PM6/17/16 3:26 PMPassReceived After 4:00 PM and closed within 24 hours

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Which field/column represents Closing date?
What does this mean--- Between <=8:00 AM to 4:00 PM --?

Please describe how Req3 passes?????

I think you should provide more details on what makes a req Pass or Fail with examples.
 
Last edited:
Upvote 0
Please describe how Req3 passes?????
Agree that this is a little confusing. It's not received between 8 and 4 so how do the rules apply?
 
Upvote 0
Well,not sure if you are with us anymore but here's a first stab at this. I can think of two problems with this right off the bat but you have to start somewhere!!

To run, you should put this function in a new public module. Then you can use it in a query like an inbuilt function:
Code:
SELECT 
    RequestQueue, 
    ReceivedDate, 
    FixedDate, 
    PassOrFail([ReceivedDate],[FixedDate]) AS Exp1
FROM Table14;


Code:
Public Function PassOrFail(Date_Recd As Date, Date_Fixed As Date) As String

Dim Time_Received As Date
Dim Date_Due As Date
Dim Weekend_Or_Holiday_Adjustment As Long
    
    Time_Received = Date_Recd - Int(Date_Recd)
    
    '-----------------------------------------------------------------------
    '//CALCULATE DATE_DUE FOR REQUESTS RECEIVED DURING NORMAL BUSINESS HOURS
    If Time_Received >= TimeValue("08:00:00") And Time_Received <= TimeValue("16:00:00") Then
        
        '//Received during normal hours so due at 5:00
        Date_Due = Int(Date_Recd) + TimeValue("17:00:00")
    
    
    '---------------------------------------------------------------------------
    '//CALCULATE DATE_DUE FOR REQUESTS RECEIVED OUTSIDE OF NORMAL BUSINESS HOURS
    Else
        
        '//Received outside of normal hours so due next day at 5:00
        If Weekday(Date_Recd) = vbFriday Then
            Weekend_Or_Holiday_Adjustment = 3
        ElseIf Weekday(Date_Recd) = vbSaturday Then
            Weekend_Or_Holiday_Adjustment = 2
        ElseIf Weekday(Date_Recd) = vbSunday Then
            Weekend_Or_Holiday_Adjustment = 1
        End If
        Date_Due = Int(Date_Recd) + TimeValue("17:00:00") + 1 + Weekend_Or_Holiday_Adjustment
    End If
    
    '-------------------------------------------
    '//RETURN PASS OR FAIL DEPENDING ON DUE DATE
    If Date_Fixed <= Date_Due Then
        PassOrFail = "Pass"
    Else
        PassOrFail = "Fail"
    End If

End Function
 
Upvote 0
Hi,

Fixed date represent the closing Date. I will simplify with the rules below.

Passing rule
1. Any request with received time at 8:00 AM or 2 hours earlier until 4:00 PM and the fixed time is 5:00 PM should be Pass.
2. Any request with received time 4:01 PM and Fixed time is within 24 hours should be Pass.

Failing rule
1.Any request with received time at 8:00 AM or 2 hours earlier until 4:00 PM and the fixed time is 5:01 PM onward should be Fail.
2. Any request with received time 4:01 PM and Fixed time is over 24 hours should be Fail.

Thanks.
Dennis
 
Upvote 0
Hi Xenou,

Thanks, i tried the code but looks like there is a little mismatch. Below data should result to a Pass. Also can it be inserted a separate received date and closing date per country. Let say for US, should be 6:00 PM - 4:00 AM due on 5 AM and same rules apply only the time that is matter.

Received DateFixed DateExp1Remarks
6/6/16 5:50 PM6/7/16 5:02 PMFailstill within 24 hours (due until 5:50 the next day)
6/16/16 5:11 PM6/17/16 5:10 PMFailstill within 24 hours (due until 5:11 the next day)

<colgroup><col span="2"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
In order to have different times for different countries we need to know what country applies. I don't see any country information in your data.
The new rules seem to be inexact. For instance, if received time is 6:00 PM and it is completed within 24 hours it is pass. But it's still after 5:00 PM the next day. Working out these cutoffs are very tricky. Worse if it's received at 5:00 AM. What then? Do we say they have 24 hours? Or is it due at 5:00 PM? That's not covered either (or only vaguely).
 
Upvote 0
Hi Xenou,

Below are the rules per country and i have some Pass and Fail sample also. The code you provided is working in regions MNL and CHN, however, i got few incorrect arguments.
Rules:
Normal Business hoursOutside Normal Business hours
Received Date
CountryTime StartTime EndClosing TimeReceived DateClosing Date
USA21:005:006:005:015:00(24 hours)
CND21:005:006:005:015:00(24 hours)
MNL8:0016:0017:0016:0116:00(24 hours)
CHN8:0016:0017:0016:0116:00(24 hours)
IND11:0020:0021:0020:0120:00(24 hours)

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>


Sample:
AR CompanyRequest QueueReceived DateFixed DateResult
USAReq16/10/16 23:346/11/16 1:48Pass
USAReq26/14/16 6:196/15/16 5:24Pass
USAReq36/24/16 3:016/25/16 15:41Fail
USAReq46/8/16 7:166/9/16 20:50Fail
MNLReq56/7/16 15:016/7/16 15:13Pass
MNLReq66/27/16 19:446/28/16 12:50Pass
MNLReq76/9/16 15:216/9/16 18:35Fail
MNLReq86/10/16 17:576/11/16 17:59Fail
CHNReq96/30/16 15:566/30/16 16:03Fail
CHNReq106/20/16 16:586/22/16 12:12Fail
CHNReq116/6/16 9:416/6/16 11:06Pass
CHNReq126/6/16 17:406/7/16 10:43Pass
INDReq136/30/16 13:396/30/16 14:01Pass
INDReq146/8/16 21:206/8/16 22:23Pass
INDReq156/6/16 19:076/6/16 23:46Fail
INDReq166/10/16 19:356/11/16 1:09Fail

<colgroup><col span="2"><col><col><col></colgroup><tbody>
</tbody>

Incorrect arguments in the Code:
Received DateFixed DateExp1Remarks
6/6/16 5:50 PM6/7/16 5:02 PMFailstill within 24 hours (due until 5:50 the next day)
6/16/16 5:11 PM6/17/16 5:10 PMFailstill within 24 hours (due until 5:11 the next day)

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top