[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

calculating time values in query

Posted on 2011-09-26
7
Medium Priority
?
288 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

649 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