Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

Hide content after 9AM in different time zones - VBScript

I would like to hide some content on my web page after 9AM. This is how I'm doing it now:

<%If FormatDateTime(Time, vbShortTime) < "09:00" Then %>
SHOW CONTENT
<%else%>
DON’T SHOW CONTENT
<%end if%>

The problem is that there are cities that are not in my time zone, and I'd like to hide the content when it's 9AM where they are. My city is ORD which is in central time. The other cities are EWR + 1hour, DEN -1hour, SFO -2hours. How could I hide the content at 9AM in each city?
Thank you for your help.
Avatar of Don Thomson
Don Thomson
Flag of Canada image

This code will allow you to figure out the TimeZone.

However - If you are hiding a folder or file on a ORD server - I don't see how you could do it - Either the file/Folder is seen or is hidden once you run the actual vbs.

http://blogs.technet.com/b/heyscriptingguy/archive/2007/11/27/hey-scripting-guy-how-can-i-retrieve-time-zone-information-for-a-computer.aspx
2 ways you could approach this depending on your setup:

if you have users logging into the site, then you could add timezone and timezone offset columns to your users table and do a calculation based off of that data. This would obviously need the user to enter in their time zone location :)

if you have a open site, meaning users don't have to log in, then you would need to use javascript to get the users local time.

<script>
$(document).ready(function () {      //-- page onload constructor if using jquery

var localTime = new Date();

if ( localTime.getHours() >= 9 )
      //-- show content
else
      //-- hide content
}
</script>
Avatar of Stefan Motz

ASKER

What I would like to hide is a form. Users are not supposed to submit it after 9AM.

I was thinking of a multidimensional array, something like this, but I can't make it work in VBScript:

Var TimeArray: Array = ( [“EWR”,1,], ( [“ORD”,0,], ( [“DEN”,-1,], ( [“SFO”,-2,]   )
Get index of my City ie: EWR
If (index= -1) then{ Reatime = Now()} else <- this prevent errors in case the user’s city is not on the list.
{  
Array Index of EWR =  0
timeDifference = TimeArray[0][1]
timeDifference = 1

RealTime = AddDate(‘h’, timeDifference , Now() )
}
after the server 9am or the users 9am?
I'd like to hide the content after the user's 9AM
then you don't need to worry about what the server time is, you just need to get the users local time. Try my 2nd solution above and see if that doesn't work for you
What jquery do I have to use? I found something similar, but this example times out instead of becoming invisible after a certain time of the day:

<html>
  <head>
    <title>Untitled Document</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
      $(document).ready( function() {
        $('#deletesuccess').delay(1000).fadeOut();
      });
    </script>
  </head>
  <body>
    <div id=deletesuccess > hiiiiiiiiiii </div>
  </body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America 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
This seems to be working, thank you very much. But how could I make the content invisible after e.g. 9:15 AM?
<=9:15 doesn't work
Thank you very much.
thanks for the points :)

to answer your question, you would need to use getMinutes() on the time. so change the if statement to:

if ( localTime.getHours() <= 9 && localTime.getMinutes() >= 15 )