Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

-Collapse +Expand ASP Classic Store

Prestwood eMagazine

January Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicLanguage Basics   Print This     
  From the June 2013 Issue of Prestwood eMag
ASP Classic Language Basics:
Get GMT Server Offset
Posted 13 years ago on 5/7/2007
Take Away: You can use JavaScript to set an IIS App var to the GMT server difference. Then use that number in your code.


Here is a technique to get the current GMT offset and use it from ASP. In JavaScript, the getTimezoneOffset function returns the number of minutes offset to GMT and you can use it to set an application variable that you use with ASP.

1. Create an ASP file called SetGMTOffSetApp.asp with the following contents.

<%@ LANGUAGE=JScript %>
  var x = new Date()
  Application("ServerGMTOffset") = 0 - new Date().getTimezoneOffset();

The "0 - " is because in getTimezoneOffset the sign of the offset is reversed. -3 hours GMT is actually returned as 3 by the function, and +8 is returned as -8.

2. In your Global ASA OnStart code, or whever you like, you can do the following:

If Application("ServerGMTOffset") = "" Then Server.Execute "SetGMTOffSetApp.asp"

So when you apply the offset in your code, remember to use the "n" option (for minutes) in the DateAdd function.
eg: GMTNow = DateAdd("n", Application("ServerGMTOffset"), Now)


Share a thought or comment...
Comment 1 of 1

If you're using SQL server, you can also use GETUTCDATE() function SQL gets it from the server's own region settings, like the UTCTime functions does in ASP.NET, so it takes into account daylight savings etc. Remember, good coding means ALL your dates should be stored in UTC time. This is the way to get it.

The SQL code would be:


It's worth doing this in your app's OnStart code (in global.asa).

If Application("ServerUTCDate") = "" Then
... get it from SQL
End If
Posted 13 years ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1246A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100536 Counter
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

©1995-2020 Prestwood IT Solutions.   [Security & Privacy]