Solved

Auto refresh a Classic ASP page after midnight every night

Posted on 2012-12-29
9
1,864 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38730865
0
 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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 to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

831 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