Print Page | Close Window

DateDiff() problems

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7205
Printed Date: 31 March 2026 at 3:07pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: DateDiff() problems
Posted By: Gullanian
Subject: DateDiff() problems
Date Posted: 12 November 2003 at 2:28pm

Writting a simple script to show time a user has been online, and the time they have been inactive for.  Should produce something along the lines of:

Active for 7 mins
Inactive for 2 mins

But instead of this it produces:

Active for 7 mins
Inactive for 41760 mins

The code to update the last active field is:

strSQL = "UPDATE " & strDatabaseTablePre & "ActiveOperators SET lastActive = '" & now() & "' WHERE operatorID = " & lngOperatorID

And the code to display the report is:

Response.write("<font  color=""#008000""><B>Online</B></font>& lt;BR>Active for <B>" &  dateDiff("n",rsCommon2("cameOnline"),rsCommon2("lastActive") ) & "</B> mins<BR>")
Response.write("Inactive for
<B>" & dateDiff("n",now(),rsCommon2("lastActive")) & "</b> mins")

Example of a database record:

Lastactive: 11/12/2003 21:21:25
CameOnline: 11/12/2003 21:14:26

Any insight as to why its producing over 41,000 would be helpful!  Thanks




Replies:
Posted By: michael
Date Posted: 12 November 2003 at 3:36pm
It should be dateDiff("n",rsCommon2("lastActive"),now())

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Gullanian
Date Posted: 12 November 2003 at 3:43pm

Tried that, produces:

-41760



Posted By: MorningZ
Date Posted: 12 November 2003 at 4:36pm

considering that is almost a month off, i'd assume you aren't comparing what you think you are comparing

in that mess above.. break it up and spit out the individual dates, a la, and if you swap the order, the mins will just come out as negative, doing an absolutel function around it makes it not matter what order they are:

Response.Write "Date 1: " & Now() & "<br />"
Response.Write "Date 2: " & rsCommon2("lastActive") & "<br />"
Response.Write "Diff in Minutes: " & dateDiff("n",Now(),rsCommon2("lastActive")) & "<br />"



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Phat
Date Posted: 12 November 2003 at 5:17pm
If i run

DateDiff("n", "11/12/2003 21:14:26", "11/12/2003 21:21:25") then i get 7

I ran it in VB so not sure what it's it doing in ASP



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net