Solved

Hide content after 9AM in different time zones - VBScript

Posted on 2014-03-20
11
399 Views
Last Modified: 2014-03-20
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.
0
Comment
Question by:romsom
  • 5
  • 5
11 Comments
 
LVL 14

Expert Comment

by:Don Thomson
ID: 39942674
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
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39942731
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>
0
 

Author Comment

by:romsom
ID: 39942745
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() )
}
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39942748
after the server 9am or the users 9am?
0
 

Author Comment

by:romsom
ID: 39942756
I'd like to hide the content after the user's 9AM
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 32

Expert Comment

by:Big Monty
ID: 39942765
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
0
 

Author Comment

by:romsom
ID: 39942826
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>
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39942850
you don't HAVE to use jquery, I just used it as an example. using the example code above, i think we can do the following:

<html> 
  <head> 
    <title>Untitled Document</title> 
    <script type="text/javascript"> 
function test() {
   var localTime = new Date();

   if ( localTime.getHours() <= 9 ) 
      document.getElementById('deletesuccess').style.display = 'none';

}
    </script>
  </head> 
  <body onload="test();"> 
    <div id=deletesuccess > hiiiiiiiiiii </div> 
  </body> 
</html>

Open in new window

0
 

Author Comment

by:romsom
ID: 39942894
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
0
 

Author Closing Comment

by:romsom
ID: 39942920
Thank you very much.
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39943041
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 )
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now