?
Solved

calculating time values in query

Posted on 2011-09-26
7
Medium Priority
?
278 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
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 600 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 93

Accepted Solution

by:
Patrick Matthews earned 1400 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

Industry Leaders: 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!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

777 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