[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 719
  • Last Modified:

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!
0
jerf26134
Asked:
jerf26134
  • 2
1 Solution
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now