Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL Dates (Mysql)
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL Dates (Mysql)

 Post Reply Post Reply
Author
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Topic: SQL Dates (Mysql)
    Posted: 13 January 2004 at 3:35pm

I am having some SQL problems with asp/mysql.  I am trying to write my script for mysql now.  Can you point me in the right direction for some examples on date formating with mysql/asp before I go and ask a question about my code.

 

thanks

--Todd

Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 4:08pm
Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 6:07pm

Ok I looked at that and tried some things but I am still having some problems.  No value gets entered in the table.  All I see is 0000-00-00 00:00:00

If I response.write onlinedate before I format I see 1/13/2004 5:06:14 PM

If I response.write onlinedate after format I see 13-1-2004 17:6:14

I am using mysql and I am using the datetime type for the two columns Logon_time, Last_Seen

Here is my code

<!--#include file='dbconnection.inc'-->
<%

onlinedate = now()
OnlineUserIp = Request.ServerVariables("REMOTE_ADDR")
strUserID = Session("userName")

onlinedate = Day(onlinedate) & "-" & Month(onlinedate) & "-" & Year(onlinedate) & " " & Hour(onlinedate) & ":" & Minute(onlinedate) & ":" & Second(onlinedate)

lastseen = Day(onlinedate) & "-" & Month(onlinedate) & "-" & Year(onlinedate) & " " & Hour(onlinedate) & ":" & Minute(onlinedate) & ":" & Second(onlinedate)

'Set timeout in minutes
strTimeout = 5
StrOnlineTimedout = dateadd("n",-strtimeout*3,onlinedate)

StrSql = "Select * From Active_Users Where User_ID='" & strUserID & "'"
Set rs1 = adoCon.Execute (StrSql)

'Check if users id exists in active users database
if rs1.eof then
'Add user to database because they dont exist
StrSql = "INSERT INTO active_Users (Logon_time,User_ip,Last_Seen,Last_Page,User_ID) " &_
"VALUES ('" & onlinedate & "','" & OnlineUserIp & "','" & lastseen & "','" &_
request.servervariables("path_info") & "','" & strUserID & "')"
adoCon.Execute (StrSql)
else
'There Still active so lets update their info
StrSql = "UPDATE active_users SET Last_Seen='" & lastseen & "', Last_Page='" &_
request.servervariables("path_info") & "' WHERE User_ID='" & strUserID & "'"
adoCon.execute (StrSql)
end if

'Remove Users Who Have Timed Out
StrSql = "DELETE FROM active_users WHERE Last_Seen < " & StrOnlineTimedout &"
adoCon.execute (StrSql)


%>

 

Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 6:38pm

OK I think I have it.  But how can I still do the compare on my delete line?

 

<!--#include file='dbconnection.inc'-->


<%
function mySqlDate(myDate)

    mySqlDate = Year(myDate) & "-" & Month(myDate) & "-" & Day(myDate) & " " & Hour(myDate) & ":" & Minute(myDate)  & ":" & Second(myDate)

end function
%>

<%

onlinedate = now()

OnlineUserIp = Request.ServerVariables("REMOTE_ADDR")
strUserID = Session("userName")

'Set timeout in minutes
strTimeout = 5
StrOnlineTimedout = dateadd("n",-strtimeout*3,onlinedate)

StrSql = "Select * From Active_Users Where User_ID='" & strUserID & "'"
Set rs1 = adoCon.Execute (StrSql)

'Check if users id exists in active users database
if rs1.eof then
'Add user to database because they dont exist
StrSql = "INSERT INTO active_Users (Logon_time,User_ip,Last_Seen,Last_Page,User_ID) " &_
"VALUES ('" & onlinedate & "','" & OnlineUserIp & "','" & mySqlDate(now()) & "','" &_
request.servervariables("path_info") & "','" & strUserID & "')"
adoCon.Execute (StrSql)
else
'There Still active so lets update their info
StrSql = "UPDATE active_users SET Last_Seen='" & mySqlDate(now()) & "', Last_Page='" &_
request.servervariables("path_info") & "' WHERE User_ID='" & strUserID & "'"
adoCon.execute (StrSql)
end if

'Remove Users Who Have Timed Out
'StrSql = "DELETE FROM active_users WHERE Last_Seen < " & StrOnlineTimedout &"
'adoCon.execute (StrSql)

%>

Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 6:51pm

This is the part I am talking about with the compare and delete

strTimeout = 5
StrOnlineTimedout = dateadd("n",-strtimeout*3,mySqlDate(onlinedate))

strOnlineTimedout = mySqlDate(StrOnlineTimedout) 

'StrSql = "DELETE FROM active_users WHERE Last_Seen < " & StrOnlineTimedout &"
'adoCon.execute (StrSql)

 

I am real close just can't get it though.  When I response.write the value I see what I want.  I just get this error with the above code.

Syntax error

/login/mysql/activeusers.asp, line 42

StrSql = "DELETE FROM active_users WHERE Last_Seen < " & StrOnlineTimedout  &
----------------------------------------------------- -----------------------^


Edited by twooly
Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2004 at 8:26pm

Got it

 

StrSql = "DELETE FROM active_users WHERE Last_Seen < '" & StrOnlineTimedout & "'"

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.