We help IT Professionals succeed at work.

How to get GMT in ASP

jerf26134
jerf26134 asked
on
Medium Priority
735 Views
Last Modified: 2008-02-01
I have a database that is used across the country within the company I work with.  I have a search page the searches area codes and returns all matching area codes with the current time in that area code.  

I would take the server time, but unfortunately, the site is located on a few servers to balance the load and some of the servers are not located in the same timezone as the others.

Is there anyway to have the server calculate GMT and use that as the basis of the time calculation, or do I have to get the local time from the client and then calculate it that way?  I can't believe that there isnt anyway to do this from the server.  Please help!
Comment
Watch Question

Commented:
Check this out

<script language="JSCRIPT" runat="SERVER">
  //this is jscript
   function getTimezoneOffset() {
         var dtmNow = new Date();
         var intOffset = dtmNow.getTimezoneOffset() / 60
         intOffset = -(intOffset +1)
         return(intOffset);
    }
</script>
<%
   'this is vbscript
   response.write formatdatetime(dateadd("h",getTimezoneOffset,Now),3)
%>


hongjun

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Maybe it's too late at night for me, but all I get when I try it is a type mismatch:

Type mismatch: '[string: "function getTimezone"]'

I had it write the variable getTimezoneOffset and it returned the whole script as a string instead of a time:
function getTimezoneOffset() { var dtmNow = new Date(); var intOffset = dtmNow.getTimezoneOffset() / 60 intOffset = -(intOffset +1) return(intOffset); }

Any ideas on what I might be doing wrong?  It could just be because its late for me and I am not thinking straight.

Author

Commented:
Ok, I got it working with some tweaking.  Here is the final answer I came to in case anyone is looking for it in the future:

time.asp --
<script language="jscript" runat="server">
   d = new Date();
   tz = -d.getTimezoneOffset()/60;
</script>

<%
gmtime = DateAdd("h",tz,now)
gmtime = FormatDateTime(gmtime, 3)

response.write gmtime
%>
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.