Auto refresh a Classic ASP page after midnight every night

hcaadev
hcaadev used Ask the Experts™
on
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!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
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>

Author

Commented:
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.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
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

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
Software Engineer
Commented:
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

Author

Commented:
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.
Robert SchuttSoftware Engineer

Commented:
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.

Author

Commented:
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.

Author

Commented:
Thanks for the input and solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial