Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Time calculation

BigPete85BigPete85 Member Posts: 30
I have 2 text boxes where times are being entered. In the 3rd text box i want the total hours between the two times displayed. for example 5:00AM in the first box
12:00PM in the second box

then the third box should automatically show 7.

Comments

  • dokken2dokken2 Member Posts: 532
    : I have 2 text boxes where times are being entered. In the 3rd text box i want the total hours between the two times displayed. for example 5:00AM in the first box
    : 12:00PM in the second box
    :
    : then the third box should automatically show 7.
    :
    :

    Use DateDiff function- datediff("h","5:00AM","12:00PM")

    me.textbox3.value = datediff("h",me.textbox1,me.textbox2)
  • BigPete85BigPete85 Member Posts: 30
    That code doest work if the start time is later in the day. For example if the start of the shit is 6:00pm and ends 3:00am it shoudl display 9, but instead it displays 15.

    : : I have 2 text boxes where times are being entered. In the 3rd text box i want the total hours between the two times displayed. for example 5:00AM in the first box
    : : 12:00PM in the second box
    : :
    : : then the third box should automatically show 7.
    : :
    : :
    :
    : Use DateDiff function- datediff("h","5:00AM","12:00PM")
    :
    : me.textbox3.value = datediff("h",me.textbox1,me.textbox2)
    :

  • dokken2dokken2 Member Posts: 532
    : That code doest work if the start time is later in the day. For example if the start of the shit is 6:00pm and ends 3:00am it shoudl display 9, but instead it displays 15.
    :
    : : : I have 2 text boxes where times are being entered. In the 3rd text box i want the total hours between the two times displayed. for example 5:00AM in the first box



    consider the point of reference for the function, it will be from midnight of same day. therefore, a DateDiff of 6:00PM-3:00AM, the function is starting at 6:00PM and counting back to 3:00AM [same day!] which is 15 hours earlier, or -15.

    in your example, the time frame spans two calendar days, so need

    datediff("h","6:00PM","11:59PM") - time to midnight = 5-hours [need to round up 1-hour to account for midnight starting on next day]

    datediff("h","12:00AM","3:00AM") - time from midnight next day to 3:00AM = 3-hours

    6 [5+1] + 3 = 9 hours
Sign In or Register to comment.