Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time calculation in a query 1

Status
Not open for further replies.

socomfort

Technical User
Jul 8, 2005
46
US
Hello all:

I have the following fields in a table:

StartTime (date/time datatype)
RampTime (float)
HoldTime (float)

In a query, I am calculating the following:

EndTime: Format(DateAdd("h",[HoldTime],[StartTime]),"Long Time")

This sort of works, except that fractional parts of the HoldTime are truncated and I am not sure how to include my RampTime.

The datatype for EndTime is also Date/time.
HoldTime values can include a fractional component (e.g., 11.25 hours). A ramp time might be .5 hours.

So, lets say based upon the above values that my StartTime is 8:00:00 AM, then my EndTime should be 07:45:00 PM and not 07:00:00 PM, which is what I am getting.

I appreciate any help you can provide,

Ben
 
What about this ?
DateAdd("[!]n[/!]",[!]60*[/!][HoldTime],[StartTime])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

Thanks so much for the prompt response. Your code correctly adds the RampTime component. However, there are two fields that I have to add:

EndTime = StartTime + HoldTime + RampTime

So, in the following:
DateAdd("n",60*[RampTime],[StartTime]) where [RampTime]= .5, I am wondering if I can also add [HoldTime] which is typically over ten hours. And [HoldTime] will some time has a fractional component, say, 11.25

Although the following will not work, I am trying to do something like this:

EndTime: Format(DateAdd("n",60*[RampTime],[StartTime])+DateAdd("n",60*[HoldTime],[StartTime]),"Long Time")


thanks in advance of your help,

Ben
 
Perhaps this ?
EndTime: Format(DateAdd('n',60*([RampTime]+[HoldTime]),[StartTime]),"Long Time")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That was it, dude. Thanks so much for your help!

-Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top