DatePicker one day off

6 posts, 1 answers
  1. Manu
    Manu avatar
    10 posts
    Member since:
    Jun 2016

    Posted 19 Jun Link to this post

    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

  2. Answer
    Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Jun Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Manu
    Manu avatar
    10 posts
    Member since:
    Jun 2016

    Posted 21 Jun in reply to Maria Ilieva Link to this post

    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 ...

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 22 Jun Link to this post

    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
  6. Manu
    Manu avatar
    10 posts
    Member since:
    Jun 2016

    Posted 22 Jun in reply to Maria Ilieva Link to this post

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

    Best regards.

    Manu

  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 Jun Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready