Solved

Change time based on client timezone

Posted on 2011-02-14
6
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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