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!
jerf26134Asked:
Who is Participating?
 
hongjunCommented:
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
0
 
jerf26134Author 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.
0
 
jerf26134Author 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
%>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.