Time problem

Results 1 to 2 of 2

Thread: Time problem

  1. #1
    Join Date
    Dec 1969

    Default Time problem

    I&#039;m subtracting a number to the hour of the current time as it goes through a For Loop. However it doensn&#039;t work very consistently I get values such as:<BR><BR>29/12/1899 13:22:53<BR>...<BR><BR>My code is below, the timeDiff() function returns the difference between the current hour and the hour stored in the &#039;theTime&#039; variable so if the current time was 1:00:00 and theTime stored 5:00:00 timeDiff would return 4:<BR><BR>theHours=timeDiff("h", theTime, time())<BR><BR>FOR i=1 TO theHours<BR><BR>IF i = cInt(theHours)THEN<BR>backLog=time()<BR>ELSE<BR>ba ckLog=cDate(dateAdd("h",-theHours+i, time()))<BR>END IF<BR><BR>response.write backLog & "<BR>"<BR><BR>NEXT<BR><BR>the problem seems to occur when the time goes past midnight, what do I need to do to account for this.<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default Use DateDiff...

    &nbsp;<BR>Yes, DateDiff works fine with "h" and "n" and "s".<BR><BR>Where did you find docs for TimeDiff???<BR><BR>They aren&#039;t here:<BR>http://msdn.microsoft.com/library/en-us/script56/html/vtorifunctions.asp<BR><BR>Oh! I see. DateDiff would have the same problem. Never mind.<BR><BR>Hmmm...<BR><BR>Okay, simple as this:<BR><BR>theHours = DateDiff( "h", theTime, time() )<BR>If theHours &#060; 0 Then theHours = theHours + 24<BR><BR>Make sense?<BR><BR>If theTime is 1:00:00 AM and time() is 11:00:00 PM, then you will get -22 hours as the difference. (Or maybe I have it backwards, but in any case...)<BR><BR>But, of course, *WE* know that in truth the difference is 2 hours, but the 1AM time is the next day.<BR><BR>And shouldn&#039;t you be doing<BR><BR>For i = 0 To theHours?<BR><BR>After all, theHours *could* be zero!<BR><BR>You don&#039;t need the call to cDate in that code.<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