Solved

Change time based on client timezone

Posted on 2011-02-14
6
585 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:xDJR1875
Comment Utility
Why not just use the GMT time in all records?
0
 
LVL 1

Author Comment

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

Expert Comment

by:Todd Gerbert
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
>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
Comment Utility
Followed the 3rd link and it was what I needed. Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Glad to help :-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

9 Experts available now in Live!

Get 1:1 Help Now