SteveL13
asked on
Subtracting one time from another time
I have two fields on a form. One is "StartTime" The other is "EndTime"
I am trying to subtract StartTime from EndTime and get the right result.
If StartTime is 10:25 am and StopTime is 11:00 am I want to see 00:35 as the result.
In my result field I have:
=[txtStopTime]-[txtStartTi me]
But I'm getting 0;45
????
--Steve
I am trying to subtract StartTime from EndTime and get the right result.
If StartTime is 10:25 am and StopTime is 11:00 am I want to see 00:35 as the result.
In my result field I have:
=[txtStopTime]-[txtStartTi
But I'm getting 0;45
????
--Steve
Use DateDiff() to subtract dates.
ASKER
Hmmm. I'm getting 0:45 instead of 0:35 (minutes)
How about:
=format([txtStopTime]-[txt StartTime] , "hh:mm")
But what if one of those values is missing(NULL)? In that case, this will return a NULL value.
=format([txtStopTime]-[txt
But what if one of those values is missing(NULL)? In that case, this will return a NULL value.
Will you ever have an instance where the txtStartTime is before midnight and txtStopTime is after midnight (the next morning)?
CVDate([txtStopTime])-CVDa te([txtSta rtTime]) is the clean method and will return 0:35.
So something else is going on.
/gustav
So something else is going on.
/gustav
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All suggestions have returned 0:45
??
Bot the start and end time fields are short time format. Might this be a problem?
??
Bot the start and end time fields are short time format. Might this be a problem?
@Pat,
Yes, minutes is generally 'nn', but in this format VBA will interpret it as minutes anyway; try it. But good point, it should be "hh:nn".
Yes, minutes is generally 'nn', but in this format VBA will interpret it as minutes anyway; try it. But good point, it should be "hh:nn".
Then your times are not what you think they are.
Short Time simply reflects how the data is displayed. Remove the formatting on that field to see the full data.
Short Time simply reflects how the data is displayed. Remove the formatting on that field to see the full data.
ASKER
They are Date/Time, General Date fields in the table.
Open your table in design view, change the format of those fields (assuming they are bound controls) to nothing. Then open the table scroll to the row with the data you are trying to view, take a screen shot, and post it here.
OK, now try a query.
SELECT [Load Sch Start], [Load Sch Complete]
, Format([Load Sch Complete] - [Load Sch Start], "hh:nn") as LoadTime
FROM yourTable
and display those results.
SELECT [Load Sch Start], [Load Sch Complete]
, Format([Load Sch Complete] - [Load Sch Start], "hh:nn") as LoadTime
FROM yourTable
and display those results.
Good question, which I cannot answer, unless the textboxes on the form are not actually bound to the right fields in your table. Generally, I give the textboxes names that are identical to the name of the field, except with a prefix:
txt_Load_Sch_Start
txt_Load_Sch_Complete
You could simply modify the RecordSource of your form to a query which contains that formatted text. The control would be blank if either [Load Sch Start] or [Load Sch Complete] was NULL, but would recalculate as each of those values was changed.
txt_Load_Sch_Start
txt_Load_Sch_Complete
You could simply modify the RecordSource of your form to a query which contains that formatted text. The control would be blank if either [Load Sch Start] or [Load Sch Complete] was NULL, but would recalculate as each of those values was changed.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now when I enter hh:nn as the format it automatically changes itself to Short Time.
And the result is still 0:45
And the result is still 0:45
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because of my own inability to provide real field names and also to even use them myself I feel I should grant awards to all who helped. I am sorry for all the confusion.
=CVDate([txtStopTime])-CVD
/gustav