Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change time based on client timezone

Posted on 2011-02-14
6
Medium Priority
?
611 Views
Last Modified: 2012-05-11
I am querying a datetime field from SQL database to show the date and time of an event. The person who sets the event date and time is in one particualar timezone (Mountain Time USA), but users may be in a different time who see the event date and time. Is there a way to have the time adjusted based on the location of the user in a different timezone? For example, if someone in California views the same info, it will subtract one hour so the time they view will coordinate with the user who sets the time?

Currently, I just have something like:  "Select right(convert(varchar(19), EventStart, 100),6) As Time from Event Where something = @something"

That gives me the time from the datetime sql field. but need to adjust it depending on where someone might be in multiple different timezones.

Thank you.
0
Comment
Question by:mlg101
6 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 34890422
Why not just use the GMT time in all records?
0
 
LVL 1

Author Comment

by:mlg101
ID: 34890436
How does that work and how do you do it? does it automatically adjust then?
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34890437
Normally I think one would always store Greenwich Mean Time (UTC) in the database, then you can always convert it to a local time for any user with DateTime.ToLocalTime() - otherwise your database needs some means to indicate which timezone the data was originally stored for.  I'm not intimately familiar with SQL's datetime, but I don't think it inherently includes this information.
0
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!

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 34896007
>The person who sets the event date and time is in one particualar timezone (Mountain Time USA)
So you probably do not need to worry about the SOURCE timezone.

Try this example
http://www.c-sharpcorner.com/UploadFile/vendettamit/1065/


Following link shows how to get client timezone using JavaScript. Its for PHP but I think would require little modification

http://stackoverflow.com/questions/13/how-can-i-determine-a-web-users-time-zone


Following link shows how to convert between different timezones

http://www.dotnetcurry.com/ShowArticle.aspx?ID=593
0
 
LVL 1

Author Closing Comment

by:mlg101
ID: 34899007
Followed the 3rd link and it was what I needed. Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34905855
Glad to help :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

972 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