This is a migrated thread and some comments may be shown as answers.

RadDateTimePicker and Timezones

1 Answer 193 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
J. David
Top achievements
Rank 1
J. David asked on 16 Aug 2011, 05:13 PM
I've searched through support and these forums, and while I've found several answers to this question, none of them specifically suit my needs.

I'm storing all my DateTime data in UTC format in my SQL 2005 database.  What I'd like is extend the RadDatePicker (and RadDateTimePicker) so that when they display a date from the DB, they automatically shift it to the loca timezone.  Then when they write any date to the DB, they shift it back to UTC.

I was thinking of creating an extension class that inherits the RadDateTimePicker and overriding the DataBind() method within it.  I'm not quite sure how to accomplish this though.  It'd be easy enough to shift the displayed date when it's read from the database, but I can't figure out how I would shift the date written back to the DB.

I've also seen places on these forums talking about AJAX and Javascript, and how the control will provide the UTC-shifted date using some of those methods.

Most of my RadPickers are databound objects on the EditTemplates of RadGrids.  They are tied to LinqDataSources and not populated in the codebehind, so manipulating the times through codebehind would take a lot of reengineering. 

Any suggestions on how I could create an extension class or manipulate the data on the client side, so that I am always looking at local time but always working with UTC in the database?

1 Answer, 1 is accepted

Sort by
0
Johny
Top achievements
Rank 1
answered on 19 Aug 2011, 01:31 PM
Hi,

As far as I know Javascript new Date() creates date object in a local time and Date.UTC creates one in UTC time. So

new Date(Date.UTC(Your DataBase Date))

should work for the binding conversion.
As to the editing you may use the getTimezoneOffset method of a date object. It return the time difference in minutes that you can applly to your date before it is updated in the data base.

I hope this helps,

Johny
Tags
General Discussions
Asked by
J. David
Top achievements
Rank 1
Answers by
Johny
Top achievements
Rank 1
Share this question
or