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

DatePicker one day off

5 Answers 645 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Manu
Top achievements
Rank 1
Manu asked on 19 Jun 2016, 10:15 AM

Hello,

I am a beginner with kendo UI and have a problem with the following input box:

<input data-role="datepicker" data-format="dd.MM.yyyy" data-bind="enabled: isEnabled, value: DateToSave" />

The date is picked correctly (displayed on the page), but after saving to the server the value in the server table is one day off. The displayed value on the page (after saving) is also one day off from the picked value.

These are the project infos:

- Telerik ASP.NET MVC 4 (v2013.3.1119)

- culture: "de-AT"

editorTemplate and DateTimeModelBinder

@model DateTime?
 
<div class="span-datepricker">
    <input name="datepicker" />
</div>
 
<script>
    $(document).ready(function () {
        // create DatePicker from input HTML element
        $("input[name='datepicker']").kendoDatePicker();
    });
</script>

using System;
using System.Globalization;
using System.Web.Mvc;
 
namespace Presentation.Host.App_Start
{
    public class DateTimeModelBinder : IModelBinder
    {
        private const string DateTimePattern = "ddd MMM dd yyyy HH:mm:ss 'GMT'zzz";
 
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue;
            if (!string.IsNullOrWhiteSpace(value))
            {
                int timeZoneInfoIndex = value.IndexOf(" (", StringComparison.Ordinal);
                if (timeZoneInfoIndex > 0)
                {
                    value = value.Substring(0, timeZoneInfoIndex);
                    return DateTime.ParseExact(value, DateTimePattern, CultureInfo.InvariantCulture).AddDays(1);
                }
 
                return DateTime.Parse(value);
            }
            return null;
        }
    }
}

ViewModel:

.....
public DateTime? DateToSave { get; set; }
...

If you could give me some hints where to start looking I'd be thankful.

Best regards.

Manu

5 Answers, 1 is accepted

Sort by
0
Accepted
Maria Ilieva
Telerik team
answered on 21 Jun 2016, 03:31 PM
Hello Manu,

I would suggest you to see the forum thread below that discusses the same issue:
http://www.telerik.com/forums/timezone-issue

I also noticed that you are manually adding one day to the saved date. Is this some kind of fix that  you try to implement.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Manu
Top achievements
Rank 1
answered on 21 Jun 2016, 08:55 PM

Hello Maria,

the AddDays(1) was a try to fix the problem I described in my 2nd post. When I omit the AddDays(1) the date is picked and saved correctly in the input box. However it does not help with the datepicker in the grid (see my 2nd post).

The link to the timezone-issue seems to be related to my 2nd post; I looked at it shortly, but I think timezone is not the issue in my case. I have to study the posts ...

0
Maria Ilieva
Telerik team
answered on 22 Jun 2016, 12:37 PM
Hello Manu,

I noticed that the ticket is marked as answered. Do let us know if you were able to fix the issue and if further assistance is needed.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Manu
Top achievements
Rank 1
answered on 22 Jun 2016, 03:25 PM

Issue is fixed - but for my 2nd post I still don't have a solution.

Best regards.

Manu

0
Maria Ilieva
Telerik team
answered on 24 Jun 2016, 11:38 AM
Hello,

Can you please elaborate more on the second issue you are still facing? Providing more information for the exact problem will help us give straight to-the-point solution.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Date/Time Pickers
Asked by
Manu
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Manu
Top achievements
Rank 1
Share this question
or