Time Difference

1. Junior Member
Join Date
Dec 1969
Posts
3

Time Difference

I&#039;m trying to create a login/logout page with ASP. I&#039;m having trouble getting the time difference in hours between the current time (when they log out) and their original login time (from the database). I need hours out to two decimal places. I cannot seem to get datediff to work to an amount of time that small. Potential exists for shifts of less than one hour. THanks a lot!

2. Senior Member
Join Date
Dec 1969
Posts
7,686

RE: Time Difference

Did you actually check the docs for the datediff function? It accurate to the second (or even milisecond)

3. Senior Member
Join Date
Dec 1969
Posts
11,247

RE: Time Difference

DateDiff("h", Date1, Date2) - hours<BR><BR>OR<BR>DateDiff("s", Date1, Date2) - Seconds<BR>

4. Junior Member
Join Date
Dec 1969
Posts
3

RE: Time Difference

It seems to be working- the problem is it is only returning whole numbers. I need 2 decimal points on the response. This is to capture hours and fractions of hours if possible. So I need 1.25 hours not 1 hour.

5. Senior Member
Join Date
Dec 1969
Posts
11,247

RE: Time Difference

DateDiff("n", Date1, Date2) - Minutes<BR>Then do the Math to find hours and parts of <BR>Hint: http://63.236.18.31/forum/asp.asp?M=520596&T=520575&F=20&P=1

6. Junior Member
Join Date
Dec 1969
Posts
3

RE: Time Difference

The problem is its giving me 3248592638 seconds. Now, the time between logging in and out is, perhaps, 180 seconds.<BR>&#060;%=DATEDIFF("s",nTime,nTimeNow)%& #062;<BR>I&#039;ve Tried:<BR>nTimeNow = NOW() nTime = DATE()<BR>nTimeNow = DATE() nTime = NOW()<BR>nTimeNow = NOW <BR>nTimeNow = DATE<BR><BR>I&#039;m not certain I&#039;ve tried every permutation but I&#039;m wondering if this thing will work unless it is 2 different dates.

7. Senior Member
Join Date
Dec 1969
Posts
11,247

Here we go

To determine the time difference we *need* to know two things<BR>1) DateTime the orginal datetime format 12/10/2002 01:58:00 PM<BR>2) Time now which can use VBScript NOW Function<BR><BR>This gives &#060;%= DATEDIFF("s", DateTime, NOW)%&#062;<BR>So you end up with something like .....<BR>Date1 = "12/10/2002 01:58:00 PM"<BR>result = DATEDIFF("s", Date1, NOW)<BR>response.write result

Posting Permissions

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