Solved

Change time based on client timezone

Posted on 2011-02-14
6
603 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

617 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