Solved

Auto refresh a Classic ASP page after midnight every night

Posted on 2012-12-29
9
1,781 Views
Last Modified: 2013-01-03
Hi,

I am having as issue, aren't we all :-)

I have created a events marquee listing using Classic ASP.  Since the scripting looks at the date and posts only the data for that date and a few days after, I need to refresh the page every night around midnight so lets removes the previous days listings,  for example, if the date is 12/12/12, any listing that had a date of 12/11/12 would not show.

I have searched the forum and did not find an answer specific to my question.

1) I am trying to refresh an IE browser window automatically after 12:00 AM

2) I know I can refresh the page at intervals (every 5 minutes, 3 hours, etc) but using this will not work.  If I refresh the page at 9:00PM due to a reboot, this will throw off the time and old listings will be present.  

3) I could refresh every few hours but I would rather not since this page will be in public view and I am unsure how it will look during the date.  This is why I want a specific time when there will be no one looking at the listing.

Does anyone have any ideas?

Thanks a bunch.  Happy Holidays!!
0
Comment
Question by:hcaadev
  • 4
  • 3
  • 2
9 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38730307
Is this a kiosk that is always open?  If not, just use your vbscript or sql to only show data for the current day.  

<%
sql="select * from myTable where fldDATE = "&date
%>
If your date field is ms sql datetime you need to normalize the date formate and get rid of the time like this.

<%
sql="select * from myTable where DATEADD(dd,0, DATEDIFF(dd,0,fldDATE)) = "&date
%>

Any time your page loads it will only use the current date's info.

If you are talking about keeping a browser open all the time as in a kiosk, you simply will use the same type of sql and use javascript to refresh the page.  I would suggest this is not a great way to work unless the browser is open 24 hrs a day for a kiosk situation.

<script>
window.setInterval("checkForRefresh();", 60000);

function checkForRefresh() {
   var now = new Date();
   if (now.getHours() === 0 && now.getMinutes() === 1) {
     
      window.refresh();
   }
}

</script>
0
 

Author Comment

by:hcaadev
ID: 38730315
Hi padas,

This is a monitor on a video wall.  The browser will always stay open.  Since it is in the public view (baggage claim of an airport) I do not want refresh during the day.  I would prefer to refresh the browser after midnight so it removed the old data.  I am using the following code to show items between a certain date range.

<%
	shownotices = 0
%>
                
<!-- Monday 12/10 -->
                
<%
    If date > #11/13/2012# and date <= #12/10/2012# Then 
    shownotices = 1
%>
                
------- blah blah HTML code ----
                
<%
	End If
%>

Open in new window


The page needs to refresh everyday to remove the old items.

I have not built the program interface yet.  This items is pending CEO approval.  Once approved then I will build a database and a front end to run the event listing but I still believe I need to refresh the page everyday to pull the new listings.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38730846
This would be one way.

<script type="text/javascript">

//60000 milliseconds is 1 minute
window.setInterval("checkForRefresh()", 60000);

function checkForRefresh() {
   var now = new Date();
   if (now.getHours() === 0 && now.getMinutes() == 1) {
      window.refresh();
   }
}

</script>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38730865
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38731332
In your original point 2) you say you can't use the normal refresh, but why not calculate the time until the moment you want to refresh as you compose the page? So if you refresh manually at 9PM you would write out a meta-refresh that tells the browser to wait 3 hours. When the page is refreshed at midnight (the standard situation) then the code generated will wait 24 hours.

Note that there may be a time difference between client and server, so in the following code I use 5 minutes past midnight as target time but you can bring that back if needed.
<%
Option Explicit

Function GetRefreshDate()
	Dim d
	d = DateAdd("d", 1, Date())
	GetRefreshDate = CDate(Year(d) & "/" & FixZero(Month(d)) & "/" & FixZero(Day(d)) & " 00:05:00")
End Function

Function FixZero(n)
	If n < 10 Then
		FixZero = "0" & n
	Else
		FixZero = "" & n
	End If
End Function

Dim intRefreshSeconds
intRefreshSeconds = DateDiff("s", Now(), GetRefreshDate())
%><html>
<head>
<title> EE Q_27980789 </title>
<meta http-equiv="refresh" content="<%= intRefreshSeconds %>">
</head>
<body>
Last refresh: <%= Now() %>
<br>
Next refresh: <%= GetRefreshDate() %>
</body>
</html>

Open in new window

0
 

Author Comment

by:hcaadev
ID: 38731465
Hi robert_schutt

I see your point.  I reviewed the code and ran.  It calculates correctly.  Let me review more and test tonight so I understand your code 100%.  I do not necessarily like grabbing code and not know what it does.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38731482
Ok, any specific part you want explained just ask. In general, what it does is: calculate a string containing the target date by adding 1 day to today's date and concatenate a time of 5 minutes past midnight. Then the DateDiff calculates the seconds from Now until the target date, which is the argument for the meta tag.
0
 

Author Comment

by:hcaadev
ID: 38740520
Thanks for the comments.  I hope to move this to a database shortly now that the listing has been approved.  Hope everyone has a happy new year.

@ robert_schutt:  Got it.  This worked great and I now understand what you did.  

@padas:  Thanks for your response.
0
 

Author Closing Comment

by:hcaadev
ID: 38740524
Thanks for the input and solution.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now