Login | |
|
 |
Dealing with working hours in VBScript/ASP - 7/6/2004 10:51:33 PM
|
|
 |
|
| |
xyzstarr
Posts: 1
Score: 0
Joined: 7/6/2004
From:
Status: offline
|
Hi. I am new in Internet Programming. I have got an ASP sscript which calculates the number of working hours and working days between two given dates. Wait let me start off like this. I am designing a helpdesk application which allows calls to be logged in at any time (including after hours, weekends as well). I store these dates in my database as they are. I have been under the impression that this script works fine but after numerous tests there seems to be inaccuracies here and there. Working hours are from 8AM to 5PM (excluding lunch break 1PM - 2PM) Working days are from Monday to Friday (excluding public holidays) All calls that are logged/fixed in after hours will be moved to the first working hour of the next working day. For example if a call is logged/fixed in at 6PM on 25/12/2004, its date and time will be adjusted to 8AM 26/12/2004. I now working with dummy dates and my test script looks like this: <HTML> <HEAD> <META HTTP-EQUIV="Content-Language" CONTENT="en-us"> <META NAME="GENERATOR" CONTENT="Microsoft FrontPage 5.0"> <META NAME="ProgId" CONTENT="FrontPage.Editor.Document"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"> <TITLE>Test of Time</TITLE> </HEAD> <BODY> <form method="POST" action="<%=Request.ServerVariables("SCRIPT_NAME")%>"> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1"> <tr> <td>Date Reported</td> <td> <input type="text" name="DateReported" size="20" value="<%=formatdatetime(Request("DateReported"),vbShortdate)%>"></td> </tr> <tr> <td>Time Reported</td> <td> <input type="text" name="TimeReported" size="20" value="<%=formatdatetime(Request("TimeReported"),vbShortTime)%>"></td> </tr> <tr> <td>Date Repaired</td> <td> <input type="text" name="DateRepaired" size="20" value="<%=formatdatetime(Request("DateRepaired"),vbShortdate)%>"></td> </tr> <tr> <td>Time Repiared</td> <td> <input type="text" name="TimeRepaired" size="20" value="<%=formatdatetime(Request("TimeRepaired"),vbShortTime)%>"></td> </tr> <tr> <td><input type="reset" value="Reset" name="B2" style="float: right"></td> <td><input type="submit" value="Submit" name="B1"></td> </tr> </table> </center> </div> </form> <% DateReported = Request("DateReported") TimeReported = Request("TimeReported") DateRepaired = Request("DateRepaired") TimeRepaired = Request("TimeRepaired") Call WorkingHoursElapsed(FormatDateTime(DateReported,vbShortDate),FormatDateTime(TimeReported,vbShortTime),FormatDateTime(DateRepaired,vbShortDate),FormatDateTime(TimeRepaired,vbShortTime)) Function WorkingHoursElapsed(startdate,starttime,enddate,endtime) Response.Write "<b>Starting Date & Time: </b>" & CDate(startdate & " " & FormatDateTime(starttime, vbShortTime)) & "<BR>" Response.Write "<b>Ending Date & Time: </b>" & CDate(enddate & " " & FormatDateTime(endtime, vbShortTime)) & "<BR>" Response.Write "<hr>" '********************start time and date************************ thehour = 0 thehour = Hour(starttime) response.write "<b>Starting Hour: </b>"& thehour & "<br>" If thehour < 8 Then starttime = FormatDateTime("08:00", vbShortTime) End If If thehour >= 17 Then startdate = DateAdd("d", 1, startdate) starttime = FormatDateTime("08:00", vbShortTime) End If Response.Write "<hr>" '************************************************************* '********************end time and date************************ '************************************************************* thehour = 0 thehour = Hour(endtime) response.write "<b>Ending Hour: </b>" & thehour & "<br>" If thehour < 8 Then endtime = FormatDateTime("08:00", vbShortTime) End If If thehour >= 17 Then enddate = DateAdd("d", 1, enddate) endtime = FormatDateTime("08:00", vbShortTime) End If Response.Write "<hr>" DateReported = CDate(startdate & " " & FormatDateTime(starttime, vbShortTime)) DateRepaired = CDate(enddate & " " & FormatDateTime(endtime, vbShortTime)) '************************************************************* '*counting the number of days between two dates*************** '************************************************************* cnt = DateDiff("d", DateReported, DateRepaired) Response.write "<b>Difference in days: </b>" & cnt &"<br>" Dim i minutes = 0 If cnt > 0 Then For i = 0 To cnt Select Case (i) Case 0 minutes = minutes + (60 * 8) Case cnt minutes = minutes + DateDiff("N", FormatDateTime("08:00", vbShortTime), endtime) If hour(endtime) > 13 Then minutes = minutes - 60 End If Case Else minutes = minutes + (60 * 8) End Select Next Else minutes = (DateDiff("N", DateReported, DateRepaired)) End If Response.Write "<hr>" '************************************************************* '********************produce output*************************** '************************************************************* Response.write "<b>New Starting Date & Time: </b>"&DateReported &"<br>" Response.write "<b>New Ending Date & Time: </b>"& DateRepaired &"<br>" Response.Write "<hr>" Response.Write minutes & " minutes<br>" Response.Write minutes/60 & " hours<br>" Response.Write minutes/60/8 & " days<br>" End Function%> </p> </BODY> </HTML> Thank you in advance
|
|
| |
|
|
|
|
|