Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hide content after 9AM in different time zones - VBScript

Posted on 2014-03-20
11
Medium Priority
?
416 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 34

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 34

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
 
LVL 34

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 34

Accepted Solution

by:
Big Monty earned 2000 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 34

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview

810 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