A Question about time conversion.

Results 1 to 2 of 2

Thread: A Question about time conversion.

  1. #1
    Join Date
    Dec 1969

    Default A Question about time conversion.

    I want to convert time. Here is an example, I would like to calculate a person&#039s time spent on a project (8:00am to 12:15pm) would be 4:15 (4Hrs and 15 minutes) of time spent. I want to convert this time to 4.25 Hrs. How could this be done?

  2. #2
    Join Date
    Dec 1969

    Default RE: A Question about time conversion.

    &nbsp;<BR>Not sure how complete an answer you are looking for, so I&#039ll do the entire thing. You just use the pieces you need:<BR><BR>This is a complete ASP page that demos *some* of the things you can do with dates and times and strings and numbers in VBScript:<BR><BR>****** FILE: ElapsedTimeDemo.asp **********<BR><BR>&LT;HTML&#062;&LT;BODY&#062;<BR> <BR>&LT;%<BR>startTime = "oops"<BR>endTime = "oops"<BR>On Error Resume Next<BR>startTime = CDate( Request.Form("StartTime" ) )<BR>endTime = CDate( Request.Form("EndTime") )<BR>On Error GoTo 0 <BR><BR>If VarType(startTime)&LT;&#062;vbDate OR VarType(endTime)&LT;&#062;vbDate Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(".. . oops... not a valid time...do what you need ...")<BR>Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;Response. Write "Elapsed time from " & startTime & " to " & endTime & "&LT;BR&#062;"<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbs p;&nbsp;&nbsp;&nbsp;minsSpent = DateDiff( "n", startTime, endTime )<BR>&nbsp;&nbsp;&nbsp;&nbsp;response.write "That is " & minsSpent & " minutes&LT;BR&#062;" & vbNewline<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;stringSpe nt = (minsSpent 60) & ":" & (minsSpent MOD 60)<BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "In hours:minutes format, that is " & stringSpent & "&LT;BR&#062;" & vbNewLine<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;timeSpent = CDate(stringSpent)<BR>&nbsp;&nbsp;&nbsp;&nbsp;Resp onse.Write "And treated as a VBScript &#039date&#039 value, that is " _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; & FormatDateTime( timeSpent, vbShortTime ) & "&LT;BR&#062;"<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&#03 9 now convert from date to hours and fractions:<BR>&nbsp;&nbsp;&nbsp;&nbsp;hours = Hour( timeSpent )<BR>&nbsp;&nbsp;&nbsp;&nbsp;minutes = Minute( timeSpent )<BR>&nbsp;&nbsp;&nbsp;&nbsp;hours = hours + ( minutes / 60 )<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "So, finally, that is " & FormatNumber( hours, 2 ) & " hours."<BR>End If<BR>%&#062;<BR><BR>&LT;HR&#062;<BR>&LT;FORM Method="Post"&#062;<BR><BR>Please enter start time: &LT;INPUT Name="StartTime" Size=12&#062;<BR>&LT;br&#062;<BR>Please enter end time: &LT;INPUT Name="EndTime" Size=12&#062;<BR>&LT;br&#062;<BR>&LT;INPUT Type=Submit Value="Push to see elapsed time."&#062;<BR>&LT;/FORM&#062;<BR><BR>&LT;/BODY&#062;&LT;/HTML&#062;<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts