Link to home
Create AccountLog in
Avatar of jerf26134
jerf26134

asked on

How to get GMT in ASP

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!
ASKER CERTIFIED SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jerf26134
jerf26134

ASKER

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.
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
%>