adding the value of two fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to have a txt field = the difference between two date/time fields and have is showed in hrs. How would I code this?
 
Basically, a date/time value is stored as number of days and fractions of a
day since December 30, 1899. So, if you subtract one date/time value from
another, you get the number of days and fractions of a day between the two.
Multiple times 24 (hours in a day) to get hours and fractions of hours.

([EndDate] - [StartDate]) * 24

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
Derek said:
I want to have a txt field = the difference between two date/time fields
and have is showed in hrs. How would I code this?
 
So it would look like this

Me.out_duration_txt.Value = ([Me.out_findate_time_txt] - [Me.out_startdate_time_txt]) * 24
 
Went back and changed the code to the following and it works, but it is not formated for time it shows up as a large number. Using 04/03/04, 23:00 and 04/04/04, 23:00 as the dates. How would I get this to read in hours, I tried setting the field format to short but then I get 0:00. The format that I have used on the date fields is: mm/dd/yy", "hh:n

Dim strdate As Dat
Dim enddate As Dat

strdate = Me.out_startdate_time_tx
enddate = Me.out_findate_time_tx

Me.out_duration_txt = (enddate - startdate) * 24
 
I don't understand what you mean by "field format to short". Set the Format
property of out_duration_txt to Standard and Decimal Places to 2. You
should get 24.00 displayed as the result of your calculation. Is
out_duration_txt bound to a field? If not, you could also explicitly set
the data type by saying:

Me.out_duration_txt = CDbl((enddate - startdate) * 24)

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
Derek said:
Went back and changed the code to the following and it works, but it is
not formated for time it shows up as a large number. Using 04/03/04, 23:00
and 04/04/04, 23:00 as the dates. How would I get this to read in hours, I
tried setting the field format to short but then I get 0:00. The format
that I have used on the date fields is: mm/dd/yy", "hh:nn
 
Back
Top