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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtracting time

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
I have two text boxes, one has a value of 09:00 AM, the other 03:00 PM, I need to get the hours between the two (6).

Any advice on the best way to do this?
 
Use the DateDiff function like this:

DateDiff("h", "9:00 AM", "3:00 PM")

This will return a value of 6. "h" specifies hours. "9:00 AM" and "3:00 PM" are dates but you do not need to specify the date because if no date is specified today's date is implied. Hope this helps.
B-)
 
thanks a lot!

Can you also tell me the syntax for minutes?

DateDiff("h:m", "9:00 AM", "3:00 PM")?


 
You need to get the minutes ("n") and do the conversion to Hrs:Mins more-or-less manually. You also need to be aware of the possability of having 'strange' stuff in a textbox and add error chacking/limits/validation code.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
I see thanks, one more thing though :)

How do I convert 360 minutes into HH:MM ?

 
i figured out how to convert min to hh:min but i have a new prob.

DateDiff("n", "9:00 PM", "3:00 PM")

returns a negative 360 ? why?

because of the neg 360 the min to hh:min function doesnt work ;(

 
DateDiff("Interval, START, End)

You need some REALLY sophisticated to start after you end. If you cant get around this, Do:

Abs(DateDiff( ... ) You will not get a negative from this!


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Thanks Michael, all works fine now ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top