Solved

Hide content after 9AM in different time zones - VBScript

Posted on 2014-03-20
11
403 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

13 Experts available now in Live!

Get 1:1 Help Now