Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Dealing with working hours in VBScript/ASP

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,1120
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Dealing with working hours in VBScript/ASP
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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
 
 
Post #: 1
 
 Re: Dealing with working hours in VBScript/ASP - 8/17/2004 10:01:33 PM   
  Matt

 

Posts: 30
Score: 0
Joined: 8/17/2004
From: United Kingdom
Status: offline
That's a lot of Code.

I need to know what the errors are or we could be here all day.

(in reply to xyzstarr)
 
 
Post #: 2
 
 Re: Dealing with working hours in VBScript/ASP - 5/5/2005 4:14:13 AM   
  JHigginson

 

Posts: 2
Score: 0
Joined: 5/5/2005
From:
Status: offline
The Case 0 code is wrong, it should be:

Case 0
minutes = DateDiff("N",starttime,FormatDateTime("17:00",vbShortTime))

(in reply to xyzstarr)
 
 
Post #: 3
 
 Re: Dealing with working hours in VBScript/ASP - 5/5/2005 4:34:52 AM   
  JHigginson

 

Posts: 2
Score: 0
Joined: 5/5/2005
From:
Status: offline
Also, don't know why this bit of code is in there but I took it out to get the correct num of working hours:

If hour(endtime) > 13 Then
minutes = minutes - 60
End If

(in reply to xyzstarr)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Dealing with working hours in VBScript/ASP Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts