Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2007, 07:12 AM
Registered User
 
Join Date: Dec 2007
Location: Lahore, Punjab, Pakistan.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to may29adil Send a message via Yahoo to may29adil
Default

i m sending you email at your email address woodyz@learntoprogramnow.com there is a attachment please dowload it

 
Old December 19th, 2007, 09:03 AM
Registered User
 
Join Date: Dec 2007
Location: Lahore, Punjab, Pakistan.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to may29adil Send a message via Yahoo to may29adil
Default

Start_Time = "11/11/07 01:58PM"
End_Time = "11/11/07 02:05PM"


response.write "Difference in hours: " & DateDiff("h", Start_Time, End_Time)
response.write "Difference in minutes: " & DateDiff("n", Start_Time, End_Time)

it response 1:07 whenever person spent total time only 0:07 so this is the problem as 60 mints are added by itself.

so please let me know

Thanks
Adil irhad
 
Old December 19th, 2007, 02:28 PM
Authorized User
 
Join Date: Oct 2003
Location: Denver, CO, USA.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The following ASP code:

    Dim start_time
    Dim end_time
    start_Time = "11/11/07 01:58PM"
    end_time = "11/11/07 02:05PM"
    Response.Write("Difference in hours: " & DateDiff("h", start_time, end_time))
    Response.Write("<BR>")
    Response.Write("Difference in minutes: " & DateDiff("n", start_time, end_time))

Generates the following (correct) result:

    Difference in hours: 0
    Difference in minutes: 7

If you are getting a different result, there is something else in the code that is causing the problem. I've used DateDiff() extensively and have never seen an inaccuracy.
 
Old December 19th, 2007, 03:47 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The difference in hours between 1:58 and 2:05 IS 1 hour. It is the same as the divfference between 1 and 2.

If you want to show hours and minutes, then you can do thus:
Get the minutes.
Use the minutes to calculate the hours (minutes/60 rounded down)
Use the mod operator to calc the minute: minutes mod 60

If you need help doing this, let me know and I'll put together a simple example


Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit
 
Old December 22nd, 2007, 08:42 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's some code, I could use some help with. It's used to track status when an agent changes state, i.e. Ready/Not Ready or Login/Logout. There's flaw somewhere both with when the time goes above a minute and/or above 1 hour. Agents are going to lunch for 30-40 minutes, then coming back to a status that says they've been gone over an hour. Any ideas? Thanks.


' The string returned in endDateTime is of the form "MM/DD/YYYY HH:MM:SS [AM/PM]"
' Extract just the time and the AM/PM indicator

strArray = split(lastupdate," ")

sub CalculateStatusTime (eventDateTimeIn)
  ' The string returned in eventDateTime is a string of the form "MM/DD/YYYY HH:MM:SS [AM/PM]"
  ' The difference between current date/time and event date/time give the time that the agent is in the current status
  ' dateDiff calculates the difference between two date values and can return this in seconds, minutes, hours, et cetera
  strArray = split(eventDateTimeIn," ")
  EventHappenedDateTime = CDate(strArray(0) & " " & strArray(1) & " " & strArray(2))
  CurrentDateTime = CDate(Date() & " " & Time())
  StatusSeconds = DateDiff("s",EventHappenedDateTime,CurrentDateTime )
  StatusMinutes = Round((StatusSeconds / 60),0)
  StatusHours = Round((StatusSeconds / 3600),0)
  StatusDays = Round((StatusSeconds / 86400),0)
  StatusSeconds = StatusSeconds - (StatusMinutes * 60)
  If StatusSeconds < 0 Then StatusSeconds = StatusSeconds + (1 * 60)
  StatusMinutes = StatusMinutes - (StatusHours * 60)
  If StatusMinutes < 0 Then StatusMinutes = StatusMinutes + (1 * 60)
  StatusHours = StatusHours - (StatusDays * 24)
  If StatusHours < 0 Then StatusHours = Statushours + (1 * 24)
  If StatusHours > 12 Then StatusDays = StatusDays - 1
  If StatusMinutes < 10 Then
    If StatusMinutes = 0 Then StatusMinutes = "00"
    If StatusMinutes = 1 Then StatusMinutes = "01"
    If StatusMinutes = 2 Then StatusMinutes = "02"
    If StatusMinutes = 3 Then StatusMinutes = "03"
    If StatusMinutes = 4 Then StatusMinutes = "04"
    If StatusMinutes = 5 Then StatusMinutes = "05"
    If StatusMinutes = 6 Then StatusMinutes = "06"
    If StatusMinutes = 7 Then StatusMinutes = "07"
    If StatusMinutes = 8 Then StatusMinutes = "08"
    If StatusMinutes = 9 Then StatusMinutes = "09"
  End If
  If StatusSeconds < 10 Then
    If StatusSeconds = 0 Then StatusSeconds = "00"
    If StatusSeconds = 1 Then StatusSeconds = "01"
    If StatusSeconds = 2 Then StatusSeconds = "02"
    If StatusSeconds = 3 Then StatusSeconds = "03"
    If StatusSeconds = 4 Then StatusSeconds = "04"
    If StatusSeconds = 5 Then StatusSeconds = "05"
    If StatusSeconds = 6 Then StatusSeconds = "06"
    If StatusSeconds = 7 Then StatusSeconds = "07"
    If StatusSeconds = 8 Then StatusSeconds = "08"
    If StatusSeconds = 9 Then StatusSeconds = "09"
  End If
End sub
 
Old December 23rd, 2007, 12:57 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My suggestion is that you take some time to refactor this code into small, testable, pieces so you can prove to yourself that each part does what you want it to.

Perhaps you can clarify things a bit? I can't make out what the result of this code is. That is, how is it used? You set a lot of variables, but there is no indication of where these variables are declared, or how they are used outside of this function.

This look a bit complicated for something as simple as what you say you are trying to do.


Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit
 
Old December 24th, 2007, 12:19 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I ended up swapping out the "round" commands with "int" and using mod to make the counters flip at 60 where appropriate. With "round", it was setting the minutes to 1 at the 30+ second mark. Anyhow it appears to be working now. This is a snippet from an asp page that pulls real time status from a database. This code displays the time since the call center agent last changed state.(ready/not ready, login/logout)

This thread pointed me in the right direction to do as you said, break out the seconds/minutes/hours, figure out the math problem and then fix it...problem solved.

Thanks!!



 
Old January 1st, 2008, 12:48 PM
Registered User
 
Join Date: Dec 2007
Location: Lahore, Punjab, Pakistan.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to may29adil Send a message via Yahoo to may29adil
Default

Thanks for reply woodyz i use your this code

Time_total_Mint = DateDiff("n", Start_Time, End_Time)

my_Hour = Time_total_Mint/60

my_Mint = Time_total_Mint mod 60

my_hour = round(my_hour,0)
my_mint = round(my_mint,0)

for example if some one login at 1:15 and logout at 2:05 the total spend time is 00:50 but the code shows it as 1:50 it is adding 1 beacause to round it of my_hour, as the my_hour => .51 it automatically adds the rounded 1

so please check it and tell me.

Thanks
Adil Irshad



 
Old January 2nd, 2008, 03:06 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Be sure your rounding is working correctly in all cases. Usint Int or Fix might be a better choice.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit




Similar Threads
Thread Thread Starter Forum Replies Last Post
convert time to minutes stolte XSLT 3 November 21st, 2008 04:12 AM
Calculate time divovsky Access 2 March 15th, 2007 03:10 PM
Calculate Time sswingle Classic ASP Basics 1 April 10th, 2006 08:30 AM
calculate time between two dates RMorales2831 Access 1 February 13th, 2004 11:38 PM
Calculate two times to find out how long they stay edkeyte Javascript How-To 0 January 19th, 2004 08:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.