Solved

calculating time values in query

Posted on 2011-09-26
7
228 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
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now