CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Timezones and Databases - The Easy Solution

Print topic Send  topic

Author Message
marcwolf


Posts: 361
Posted: 07/12/2004, 10:53 PM

Hi Folks..
I decided to putblish this so that it might help others.

The Web is everywhere, in every country, and thats means that the server might not be in the same location as the customers.

Often we use the 'NOW' function on the server to give the user the current date.. But if the server is in the US and the customer in Australia - The 'NOW' will be incorrect.

But how does the server know where the client is.. or even the database.

Ok - a very easy solution is this.

on the clients login screen create a hidden field and populate it with the results of this

  
function ServerTime(){  
  
 	var d, tz;  
   	d = new Date();  
   	tz = d.getTimezoneOffset();  
    return tz  
}  

You can do the same in the GLOBAL.ASA of the web machine

Store both values in the session for the client and the application for the server.
What this gives us if the number of minutes difference between GMT and the two locations.

Finally - store all dates in the database at GMT time and add/subtract the offsets to get the right time.

for instance..

Server NOW to Client NOW = Server Now - Server offset + client offset

Client enters a values to be put in the DB

DB Date = Client Date - Client Offset

DB Date to Server Date = DB Date + Server Offset

and all possible permutations.

If you move your server, DB, or open the application to the international market there is NO change to the processes..

Believe me - this took a lot of lost hair and bit-snits before we got it to work.. but it does work very well.

Take Care and enjoy

Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.