How to get GMT in ASP

Posted on 2006-03-24
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!
Question by:jerf26134
    LVL 33

    Accepted Solution

    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)
       'this is vbscript
       response.write formatdatetime(dateadd("h",getTimezoneOffset,Now),3)


    Author Comment

    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 Comment

    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;

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

    response.write gmtime

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now