Link to home
Start Free TrialLog in
Avatar of hcaadev
hcaadevFlag for United States of America

asked on

Auto refresh a Classic ASP page after midnight every night

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!!
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

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>
Avatar of hcaadev

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hcaadev

ASKER

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.
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.
Avatar of hcaadev

ASKER

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.
Avatar of hcaadev

ASKER

Thanks for the input and solution.