marcwolf
Posts: 361
|
Posted: 07/12/2004, 10:52 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!!!!!!!
|
|
|
dhempy
Posts: 40
|
Posted: 07/13/2004, 6:22 AM |
|
That's good stuff, Dave. Thanks for sharing!
-another dave
_________________
David Hempy
Director of Broadcast and Education Technology
Kentucky Educational Television
800-333-9764 |
|
|
LV
|
Posted: 07/13/2004, 7:03 AM |
|
Thanks for sharing.
|
|
|
DonB
|
Posted: 07/13/2004, 7:32 PM |
|
I'd strongly recommend server-based time function (most SQL implementations
have a "Now" or equivalent). Use that function in your queries, not a
client-side "Now". Having a client submit a value for "now" is asking for
trouble. This can often be accomplished by declaring the datetime column to
have a default value, too - then there is nothing required in the INSERT
statements at all for defining what "now" really is.
--
DonB
logging at http://www.gotodon.com/ccbth, and blogging at http://ccbth.gotodon.net
"LV" <LV@forum.codecharge> wrote in message
news:240f3eb97affa4@news.codecharge.com...
> Thanks for sharing.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
marcwolf
Posts: 361
|
Posted: 07/13/2004, 9:13 PM |
|
Don - that can be a problem - far better to convert all back to GMT.. including the server NOW().
If the server is to display a page that has a date field, and you wanted it filled with the current date the you have to make sure that the end user will see the current date ACCORDING to their time..
For instance. Our USA server is 10 hours difference from us here in Brisbane.
If our clients (who are also here) called up a screen that had a default date in it - we would want that date to be HERE.. not 10 hours away.
And we also have clients in Perth who are 3 hours behind us.
So.. our Perth folks add a record at 9am and then update it again in 2 hours time... the head office in Brisbane would like to know that the record was entered at 12pm their time and was then updated again at 2pm.
But when the Perth folks retireve their record - they should still see the time that they created it - 9am.
And things can get really interesting when you want to have reminder tasks and schedules that cross timelines too.
Our solution can handle all of those with ease by reducting the internal date time factor to GMT, and then re-displaying the details to the Clients local.
Using the Server date time can be an issue if one changes hosting companies etc.
I have seen horror code in an app that read something like this..
Date1 = date1 - (3 hours) if date1 < "11/02/02'" ' Nb - server moved from colardo
Just my views.
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
|
|
|
|