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

RadeDatePicker and Daylight Savings

2 Answers 71 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Daniel Probert
Top achievements
Rank 1
Daniel Probert asked on 22 Jul 2009, 07:31 AM
Hi there.
Unsure if I'm missing something here.

I have a RadDatePicker on my form.
The user enters a date (e.g. 6th June 2009)

When I attempt to get the date from this combox box in Javascript, (using get_selectedDate()) I'm returned a DateTime of... 5th June 2009 11:00pm

Given we'e in Daylight Savings at the moment, I can see what's happening: It's applying the local TimezoneOffset to the date in the control to convert to GMT (if i do get_selectedDate().getTimezoneOffset() I get -60)

So why is this happening, and what can I do to stop it?

If a user chooses 6th June 2009 in the date picker, then I expect to get 6th June 2009 when i get the selected date in Javascript!

ASPX code for control is here:

<telerik:RadDatePicker
            ID="txtDate"
            runat="server"
            TabIndex="2"
            AccessKey="t"
            Width="220px"
            MaxLength="10"
            ToolTip="Enter a Date"
            Skin="Default"
            ClientEvents-OnDateSelected="txtDate_OnDateSelected" />

Thanks!

Daniel.

2 Answers, 1 is accepted

Sort by
0
Daniel Probert
Top achievements
Rank 1
answered on 22 Jul 2009, 09:09 AM
Update: OK, I've figured out what's going on - doesn't look like it's a Telerik issue.

One thing I forgot to say above, is that i use the DateTime i get in Javascript, and set it in the context property of the RadComboBox OnItemsRequesting event i.e. pass it back to the server with the ajax call.

On the server, the DateTime appears as a .NET DateTime - and some time between setting it in the context, and reading it on server side, the date is converted to GMT and loses an hour.

i.e.  I do this in JavaScript:
function ComboBox_OnClientItemsRequesting(sender, eventArgs) {
    var context = eventArgs.get_context();
    var txtDate = $find(txtDateClientID);
    if (txtDate != null) {
        context["TicketDate"] = txtDate.get_selectedDate();
    }
}

At this point, the DateTime in JavaScript is: June 6th 2009 00:00

On server side:
protected void ComboBox_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            DateTime date = (DateTime)e.Context["TicketDate"];
        }

At this point, the date is now: June 5th 2009 23:00

Anyone have any ideas *why* this would happen?

The only fix I can see is to do a setHours(12) to the selected date in Javascript to change the time to midday.

Cheers,
Dan.
0
Martin
Telerik team
answered on 27 Jul 2009, 02:01 PM
Hello Daniel,

I would offer you to call the ToLocalTime() method of the DateTime object on the server like this:

protected void ComboBox_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) 
    { 
        DateTime date = ((DateTime)e.Context["TicketDate"]).ToLocalTime(); 
    } 
 
I hope this helps.

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Calendar
Asked by
Daniel Probert
Top achievements
Rank 1
Answers by
Daniel Probert
Top achievements
Rank 1
Martin
Telerik team
Share this question
or