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

Calculations Regarding Time (beginner) 1

Status
Not open for further replies.

LongFeiFengWu

Technical User
Nov 9, 2001
98
US
Hello, I'm a beginner and I'm building a database/web project that tracks start/stop times for a certain selection on a drop down box. I have that page set up and the asp working great. The start and stop times go to their respective columns in the table "away data". My question is; how would i make the "total" column in the same table = the total number of minutes between "start" and "stop" time and how would the user need to input the time? ie. 1300 or 1:00? I'm using Access 2000 for the DB.
 
I wrote this up for you. I think it will help. what I would recommend is doing these calculations before inserting intot he database. if you don't want to got that route then you can replace the start and finish variables with recordset values to get the same results.
hope this helps!

<% ' I worked out two solutions just with different formats in the total results hope this helps
' note do these calculations before you insert into the table
%>
<%
'this is exactly what you wanted that being a result of minutes
'these would be the querystrings of course
dim strt1, finish1, totalT1
'declare the variables

strt1 = FormatDateTime(&quot;1:25 PM&quot;, 4)
' format into 24 hour time

finish1 = FormatDateTime(&quot;3:00 PM&quot;, 4)

response.write &quot;start time &quot; & strt1 & &quot;<br>finish time &quot; & finish1 & &quot;<br>&quot;
'test it

totalT1 = DateDiff(&quot;n&quot;, strt1,finish1)
' get the difference in minutes

response.write &quot;total minutes &quot; & totalT1 & &quot;<br>&quot;

'insert variables into the DB now
%>
<%
'this example is better if you want the total to be actual time values and not just minutes

dim strt, finish, totalT, CS, CM, CH

strt = FormatDateTime(&quot;1:25 PM&quot;, 4)
' format into 24 hour time

finish = FormatDateTime(&quot;3:00 PM&quot;, 4)

response.write &quot;start time &quot; & strt & &quot;<br>finish time &quot; & finish
'test it

totalT = DateDiff(&quot;s&quot;, strt,finish)
' get the difference in seconds

'below we format the total seconds into workable time for payment value
CS = totalT mod 60
IF Len(CS) = 1 Then
CS = &quot;0&quot; & CS
End If
CM = (totalT mod 3600) \ 60
IF Len(CM) = 1 Then
CM = &quot;0&quot; & CM
End If
CH = totalT \ 3600
IF Len(CH) = 1 Then
CH = &quot;0&quot; & CH
End If
converted = CH & &quot;:&quot; & CM & &quot;:&quot; & CS
response.write &quot;<br>just a better looing format, giving actual hours, minutes and seconds &quot; & converted

'insert the data into the database now
'strt finish and converted

%>
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top