Solved

calculating time values in query

Posted on 2011-09-26
7
269 Views
Last Modified: 2012-05-12
i have attached sample db.
open database- the query [qryRoundTo8]-is a create table query- it creates [tblMain]-
it queries tbl1M- and if the ClockIn field is 8:05 or less- it changes it to 8:00

I want to change it so - if it is 7:45 am to 7:59 am- it also changes to 8:00 ( both conditions cause it to change to 8:00 am
I also want to change ClockOut Field to go back to 4:30 pm - if it is between 4:31 pm to 4:45 pm.

thank you
TestA.accdb
0
Comment
Question by:davetough
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 44

Expert Comment

by:GRayL
ID: 36601904
Are you tring to round the times to the nearest quarter hour?  If so, what are the rules for the other three?  In fact after reading your question again, I really have no idea what you are asking.  Please try again.
0
 

Author Comment

by:davetough
ID: 36602135
between 7:45 am and 8:05 am - I want time display 8:00 am
for ClockIN

between 4:30 pm and 4:45 pm- i want time to display 4:30 pm for TimeOut

thank you
0
 
LVL 44

Expert Comment

by:GRayL
ID: 36602284
And what about the 8:07 arrival and the 4:47 departure?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:almander
ID: 36602287
This formula should work, just replace with the date fields for the other values.

In: DateAdd("n",Round(DateDiff("n",DateValue([MaxOfIn]),[MaxOfIn])/60,0.5)*60,DateValue([MaxOfIn]))
0
 

Author Comment

by:davetough
ID: 36602574
8:07 arrival should be 8:07
and 4:47 should be 4:47
only thing changes when it is between 7:45 and 8:05   / and 4:30 and 4:45

almander:
I plugged in your code for clock in- thought it was working - but when I used 7:44 it still displayed 8:00 and when I used 8:06 - it still went back to 8 -
maybe i am not doing correctly
0
 
LVL 10

Assisted Solution

by:Michael Vasilevsky
Michael Vasilevsky earned 150 total points
ID: 36634368
You could use multiple queries or one custom function like:

Function UpdateTime(dTime As Date) As Date

        If TimeValue(dTime) > #7:45:00 AM# And TimeValue(dTime) <= #8:05:00 AM# Then
            UpdateTime = #8:00:00 AM#
        Else
       
            If TimeValue(dTime) > #4:31:00 PM# And TimeValue(dTime) <= #4:45:00 PM# Then
                UpdateTime = #4:30:00 PM#
               
            Else
                UpdateTime = TimeValue(dTime)
            End If
        End If

End Function

See copy of query in the attached.
TestA.accdb
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 350 total points
ID: 36650767
This seems to be working:


SELECT fdate, 
    fname, 
    fcode, 
    IIf(TimeValue([MaxOfIn]) >= #7:45:00# And TimeValue([MaxOfIn]) <= #8:05:00#, DateValue([MaxOfIn]) + #8:00:00#, [MaxOfIn]) AS ClockIn, 
    MaxOfLunch AS Lunchtime, 
    MaxOfRLunch AS Returned, 
    IIf(TimeValue([MaxOfOut]) > #16:30:00# And TimeValue([MaxOfOut]) <= #16:45:00#, DateValue([MaxOfOut]) + #16:30:00#, [MaxOfOut]) AS ClockOut, 
    Below 
INTO tblMain
FROM tbl1M;

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question