Classic ASP Check if 1 minute has passed if so trigger command - asp-classic

I am trying to check the current time VS the database time and display a message.
This is my second attempt but it's not working correctly, as you can see below, I am doing something wrong. Please help.
Thanks.
<%
Function ConvertToUnixTimeStamp(input_datetime) 'As String
Dim d : d = CDate(input_datetime)
ConvertToUnixTimeStamp = CStr(DateDiff("s", "01/01/2018 00:00:00", d))
End Function
'Response.write ("<BR><BR>Current Time Now: ") & ConvertToUnixTimeStamp(Now)
time_from_db = 11293015 + 60 'This would be the time from the database. It is generated using ConvertToUnixTimeStamp(Now) + 60
Response.write "Current Time: " & ConvertToUnixTimeStamp(Now) & "<BR><BR>"
Response.write "Time from DB: " & time_from_db & "<BR><BR>"
Response.write "<BR><BR>"
Response.write "Update DB with this time (Added 1 minute): " & ConvertToUnixTimeStamp(Now) + 60 & "<BR><BR>"
If ConvertToUnixTimeStamp(Now) > time_from_db then
Response.write("<BR>Current Time is Greaten then DB")
else
Response.write("<BR>DB Time is Newer then Current Time")
end if
%>

If ConvertToUnixTimeStamp(Now) > time_from_db then
this will never return true, as your function is converting the time to a STRING, and a string cannot be greater than another string.
I made some minor changes in your code, mainly explicitly converting variables into their data type (ex: CInt, CStr, etc).
<%
Function ConvertToUnixTimeStamp(input_datetime) 'As String
Dim d : d = CDate(input_datetime)
ConvertToUnixTimeStamp = DateDiff("s", "01/01/2018 00:00:00", d)
End Function
'Response.write ("<BR><BR>Current Time Now: ") & ConvertToUnixTimeStamp(Now)
time_from_db = 11293015 + 60 'This would be the time from the database. It is generated using ConvertToUnixTimeStamp(Now) + 60
Response.write "Current Time: " & ConvertToUnixTimeStamp(Now) & "<BR><BR>"
Response.write "Time from DB: " & time_from_db & "<BR><BR>"
Response.write "<BR><BR>"
Response.write "Update DB with this time (Added 1 minute): " & ConvertToUnixTimeStamp(Now) + 60 & "<BR><BR>"
If CInt( ConvertToUnixTimeStamp(Now) ) > time_from_db then
Response.write("<BR>Current Time is Greaten then DB")
else
Response.write("<BR>DB Time is Newer then Current Time")
end if
%>

Related

Internal Server Error 500 w/ IIS Log

I am getting some errors on my classic asp website. When the website runs for the first time it sometimes does an Internal Server Error. Then a refresh would fix it. I decided to check my IIS logs to see what the problem is but i can't interpret it. Here is the log line
2013-12-09 15:29:00 xx.xx.xx.xx GET / |37|80070005|Access_is_denied.__ 80 - xx.xxx.xx.xx Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36 500 0 0 702
How about setup custom pages for handle 500 and 500 100 errors?
Create some folder, let's say D:\InetPub\Web01\Err\
Add IUSR_Web01 user with write permission
In IIS for Web01 web site (sample for IIS 6.0)
Put following code in file 500.asp and 500100.asp
Option Explicit
Response.Buffer = True
Response.Expires = -1
Response.ExpiresAbsolute = #Jan 31,2000 12:30:00#
Response.Clear
Dim FS, TF, N, ASPErr
N = Now
Set ASPErr = Server.GetLastError()
Set FS = CreateObject ("Scripting.FileSystemObject")
Set TF = FS.CreateTextFile ("D:\InetPub\1click.lv\Err\500 " & "Error" & Right ("0" & Year (N), 4) & Right ("0" & Month (N), 2) & Right ("0" & Day (N), 2) & "_" & Right ("0" & Hour (N), 2) & Right ("0" & Minute (N), 2) & Right ("0" & Second (N), 2) & ".txt", True, False)
TF.Write MyErrorInfo (ASPErr, False, False, "1click.lv", "")
TF.Close
Set FS = Nothing
Response.Write MyErrorInfo (ASPErr, True, True, "1click.lv", "zam#1click.lv")
Err.Clear
The function:
Function MyErrorInfo (ASPErr, AsHTML, ShowContactInfo, WebTitle, AdminEmail)
Dim Result
Result = ""
If AsHTML = True Then
Result = Result & "<html><head><title>Error occur</title></head><body><font face=Verdana size=2>"
If (ShowContactInfo = True) Then
Result = Result & "<p align=center>"
Result = Result & "<font size=4>"
Result = Result & "<font color=""#008000"">" & WebTitle & "</font><br>"
Result = Result & "<font color=""#800000"">500 Error occur</font><br>"
Result = Result & "Please contact us by email at " & AdminEmail & " and inform about this error<br><br>"
Result = Result & "Thank you for your support!"
Result = Result & "</font>"
Result = Result & "</p>"
End If
Result = Result & "<hr>"
Result = Result & "Error number: <b>" & ASPErr.Number & "</b><br>"
Result = Result & "Error source: <b>" & ASPErr.Source & "</b><br>"
Result = Result & "Error description: <b>" & ASPErr.Description & "</b><br>"
Result = Result & "Error line: <b>" & ASPErr.Line & "</b><br>"
Result = Result & "Client IP: <b>" & Request.ServerVariables ("REMOTE_ADDR") & "</b><br>"
Result = Result & "Client Browser: <b>" & Request.ServerVariables ("HTTP_USER_AGENT") & "</b><br>"
Result = Result & "Client Referer: <b>" & Request.ServerVariables ("HTTP_REFERER") & "</b><br>"
Result = Result & "Path: <b>" & Request.ServerVariables ("PATH_INFO") & "</b><br>"
Result = Result & "Request method: <b>" & Request.ServerVariables ("REQUEST_METHOD") & "</b><br>"
Result = Result & "Request FORM: <b>" & Request.Form & "</b><br>"
Result = Result & "Request QUERY: <b>" & Request.QueryString & "</b><br>"
Result = Result & "<hr>"
Result = Result & "</font></body></html>"
Else
Result = Result & WebTitle & vbCrLf
Result = Result & "Error number: " & ASPErr.Number & vbCrLf
Result = Result & "Error source: " & ASPErr.Source & vbCrLf
Result = Result & "Error description: " & ASPErr.Description & vbCrLf
Result = Result & "Error line: " & ASPErr.Line & vbCrLf
Result = Result & "Client IP: " & Request.ServerVariables ("REMOTE_ADDR") & vbCrLf
Result = Result & "Client Browser: " & Request.ServerVariables ("HTTP_USER_AGENT") & vbCrLf
Result = Result & "Client Referer: " & Request.ServerVariables ("HTTP_REFERER") & vbCrLf
Result = Result & "Path: " & Request.ServerVariables ("PATH_INFO") & vbCrLf
Result = Result & "Request method: " & Request.ServerVariables ("REQUEST_METHOD") & vbCrLf
Result = Result & "Request FORM: " & Request.Form & vbCrLf
Result = Result & "Request QUERY: " & Request.QueryString & vbCrLf
End If
MyErrorInfo = Result
End Function

Server Time using VBScript and ASP Classic

I created an application to show a press release once the target date and time have been reached and wanted to know if this is getting the time from the server or the client because I'd like to use the server's time so that someone doesn't just change their clock in order to see it.
Here's my code:
<%
dim strDate
dim strTime
dim strTarget_time
dim strTarget_date
dim strBreak
dim strRuleBreak
dim strToday
strDate = Date()
strTime = Time()
strright_now = Now()
strTarget_time = "3:27:00 PM"
strTarget_date = "6/26/2012"
strBreak = "<br />"
strRuleBreak = "<br /><hr><br />"
strToday = Now()
response.write("<h2>TEST VARIABLES</h2>")
response.write("<p><strong>Today's date:</strong> " & strDate & strBreak)
response.write("<strong>Current time:</strong> " & strTime & strBreak)
response.write("<strong>Target date:</strong> " & strTarget_date & strBreak)
response.write("<strong>Target time:</strong> " & strTarget_time & "</p>")
response.write(strRuleBreak)
'TIME TESTER
response.write("<h2>TIME TESTER</h2>")
response.write("<p><nobr>Testing to see if it is past the target time of: " & strTarget_time & "</nobr></p>")
if strTime >= cdate(strTarget_time) then
response.write("<p>Yes, it is now " & Now() & ", which <strong>IS</strong> past the target time of: " & strTarget_time & "</p>")
else
response.write("<p>No, it is now " & Now() & ", which is <strong>NOT</strong> past the target time of: " & strTarget_time & "</p>")
end if
response.write(strRuleBreak)
'DATE TESTER
response.write("<h2>DATE TESTER</h2>")
response.write("<p><nobr>Testing to see if it is past the target date of: " & strTarget_date & "</nobr></p>")
if strToday >= cdate(strTarget_date) then
response.write("<p>Yes, it is now " & Now() & ", which <strong>IS</strong> past the target date of: " & strTarget_date & "</p>")
else
response.write("<p>No, it is now " & Now() & ", which is <strong>NOT</strong> past the target date of: " & strTarget_date & "</p>")
end if
response.write(strRuleBreak)
'DATE AND TIME TESTER
response.write("<h2>DATE AND TIME TESTER</h2>")
response.write("<p><nobr>Testing to see if it is past the target of: " & strTarget_date & " - " & strTarget_time & "</nobr></p>" & strBreak)
if strToday >= cdate(strTarget_date) AND strTime >= cdate(strTarget_time) then
response.write("<p>Yes, it is now " & Now() & ", which <strong>IS</strong> past the target of: " & strTarget_date & " - " & strTarget_time & "</p>")
else
response.write("<p>No, it is now " & Now() & ", which is <strong>NOT</strong> past the target of: " & strTarget_date & " - " & strTarget_time & "</p>")
end if
response.write(strRuleBreak)
%>
So in this case, if the time and date is AFTER 6/26/2012 3:27 PM, then the section will show. I'm mainly asking because I want to clarify whether this is client or server side time being used.
This is going to be server-side, as that is where ASP code is executed. In order to get the client-side datetime, you would need to use a script to run in the browser - generally JavaScript.

Setting up Google weather extended forecast with classic ASP

Just a little background, our marketing department has been using static weather images on their signage and asked if it would be possible to pull something that updated in realtime. Since I'm the only person in our department with any type of programming experience, and I'm a novice at best, I got asked to come up with a solution. I have worked with classic asp in the past for a couple of other small projects I've done, so I decided to go that route. I have everything working the way I want it to with the exception of the extended forecast data. In the sample below I have the variables that I want to display with a For statement to pull the extended forecast xml data for each day. But for some reason it is only pulling the the last day of the extended forecast.
If (objXMLDOM.parseError.errorCode <> 0) Then
Response.Write("<p>Error parsing XML: " & objXMLDOM.parseError.reason & "</p>")
Else
For i = 0 to 3
Set objFuture = objXMLDOM.getElementsByTagName("forecast_conditions").Item(i) 'pull the XML node for each from one to three
For Each xmlNode In objFuture.childNodes 'loop through the dom tree
If (xmlNode.nodeName = "icon") Then
strIcon1 = "<img src=""http://www.google.com" & xmlNode.Attributes.getNamedItem("data").text & """ border=""0"">" & vbCrLf
End If
If (xmlNode.nodeName = "condition") Then
strCondition1 = xmlNode.Attributes.getNamedItem("data").text & vbCrLf
End If
If (xmlNode.nodeName = "low") Then
strLow = xmlNode.Attributes.getNamedItem("data").text & vbCrLf
End If
If (xmlNode.nodeName = "high") Then
strHigh = xmlNode.Attributes.getNamedItem("data").text & vbCrLf
End If
If (xmlNode.nodeName = "day_of_week") Then
strDay = xmlNode.Attributes.getNamedItem("data").text & vbCrLf
End If
Set objFuture = nothing
Next
Next
End if
I am then outputing the 4 day forecast into my main page with the following code:
<%For Each Item in objXMLDOM.getElementsByTagName("forecast_conditions")
Response.Write ("<td>" & strDay & "<br>" & strIcon1 & "<br>" & strCondition1 & "<br>" & "Low:&nbsp" & strLow & "°F" & "<br>" & "High:&nbsp" & strHigh & "°F" & "<br>" & "</td>")
Next %>
I have been looking at this off and on for a couple of days now and just can't seem to find what I am missing to pull each day instead of the just the last one. If anyone has any suggestions I would appreciate it!
You are using the same set of variables to store the forecast data for each day. So during every iteration of your for loop you are overwriting the previous day's information.
The solution is to move the code that writes the data to the screen insideyour first for loop, like such:
If (objXMLDOM.parseError.errorCode <> 0) Then
Response.Write("<p>Error parsing XML: " & objXMLDOM.parseError.reason & "</p>")
Else
For i = 0 to 3
Set objFuture = objXMLDOM.getElementsByTagName("forecast_conditions").Item(i)
For Each xmlNode In objFuture.childNodes
...
Next
' Write to the page here
Response.Write ("<td>" & strDay & "<br>" & strIcon1 & "<br>" & strCondition1 & "<br>" & "Low:&nbsp" & strLow & "°F" & "<br>" & "High:&nbsp" & strHigh & "°F" & "<br>" & "</td>")
Next
End if

Classic ASP sub procedure call in Response.Write

I have a classic ASP question.
Attempting to do this: the recordset is a simple list of years from 1995 to 2020; and i am trying to make 2010(current year) the default selection in the drop down.
issue: I trying to call a Sub proc in "Response.Write", but it keeps giving me this error:
"Error '800a000d' Type mismatch: 'selectyear' "
Below is the code, the Attempt 1 works with out any problem. But when i move that "if" logic to a sub procedure and call it in the Request.Write, it gives me the error.
Can any one please explain why Attempt1 works and Attempt2 wouldnt.
' Attempt 1:
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td> <td> <select name='theyear' style=""WIDTH: 67px"">"
dim selyr
while not rsYEAR.EOF
if CINT(rsYEAR.fields("year")) = year(now) then
selyr = "selected"
else selyr = ""
end if
Response.Write"<option value='" & rsYEAR.fields("year") & "' "& selyr &" >" & cstr(rsYEAR.Fields("year"))
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
rsYEAR.Close
' Attempt 2:
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td> <td> <select name='theyear' style=""WIDTH: 67px"">"
dim selyr2
while not rsYEAR.EOF
Response.Write "<option value='" & rsYEAR.fields("year") & "' " & cstr(selectyear(cint(rsYEAR.fields("year")))) &" >" & cstr(rsYEAR.Fields("year"))
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
'close and clean up
rsYEAR.Close
set rsYEAR = nothing
I would greatly appreciate your response.
thank you,
Shiva
I am guessing that cint(rsYEAR.fields("year")) is throwing the error because there is data that cannot be converted to int. I would expect that to happen in both cases though.
You shouldn't need the cstr in cstr(selectyear(cint(rsYEAR.fields("year")))) in the second attempt, as I assume selectyear is already returning a string. Can you show the code for selectyear?
(How has this sat for so long without a correct answer?)
A Sub does not have a value, so you can't Response.Write it. You need to either use a function, or put the Sub call on its own line.
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td><td><select name='theyear' style=""width: 67px"">"
dim y
while not rsYEAR.EOF
y = rsYEAR.fields("year")
Response.Write "<option value='" & y & "'" & IsCurr(y) & ">" & y & "</option>"
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
rsYEAR.Close
Function IsCurr(yr)
if Cstr(yr) = Cstr(year(now)) then
IsCurr = " selected"
else
IsCurr = ""
end if
End Function
Using a sub instead of a function, this would become
rsYEAR.Open qYEAR, objconn, 0, 1
response.Write "<tr><td>Year:</td><td><select name='theyear' style=""width: 67px"">"
dim y
while not rsYEAR.EOF
y = rsYEAR.fields("year")
Response.Write "<option value='" & y & "'"
IsCurr y
Response.Write ">" & y & "</option>"
rsYEAR.MoveNext
wend
response.Write "</select></td></tr>"
rsYEAR.Close
Sub IsCurr(yr)
if Cstr(yr) = Cstr(year(now)) then
Response.Write " selected"
end if
End Sub

asp pagination problem

Hi i have a problem with this asp pagination. it seems to be putting all the links in the one row, so i think it might have something to do with the check of the int i...
but im not that familar with asp. can anyone shed any light on this problem.
the folders contain pdfs for each day of the month, named A08P2.pdf A09P2.pdf etc...
Thanks
i = 1
Set fc = f.Files
Set ff = f.SubFolders
For Each f1 in fc
intPage = cint(mid(f1.name,2,2))
chrEdition = mid(f1.name,1,1)
if chrEdition = "A" then
if i = 1 then
Response.Write "<tr>"
end if
Response.Write "<td width='40' align='center'><a href=" & sUP & f1.name & " class='blue_11px'>" & intPage & "</a></td>"
if i = 10 then
Response.Write "</tr>"
i = 0
end if
end if
i = i + 1
Next
You should move the incrementing of the i (i=i+1) inside the if...end if, since if i is 9 and you encounter two chrEditions that are not 'A' then i will become 11 and will never match the closing condition i=10:
if chrEdition = "A" then
if i = 1 then
Response.Write "<tr>"
end if
Response.Write "<td width='40' align='center'><a href=" & sUP & f1.name & " class='blue_11px'>" & intPage & "</a></td>"
if i = 10 then
Response.Write "</tr>"
i = 0
end if
i = i + 1
end if

Resources