asp.net-mvckendo-uikendo-asp.net-mvckendo-datepickerkendo-datetimepicker

Kendo DateTimePicker set current hour 12:00 AM instead of DateTime.Now


As it can be seen on DateTimePicker / Basic usage, the example I used below sets the current hour 12:00 AM instead of DateTime.Now when pressing the link at the footer of DateTimePicker. How to fix it?

@(Html.Kendo().DateTimePickerFor(m => m.VisitDate)
    .Animation(true)
    .Format("dd/MM/yyyy HH:mm")
    .TimeFormat("HH:mm")
    .Min(new DateTime(1900, 1, 1)) 
    .Max(new DateTime(2099, 12, 31)) 
    .Footer(true)
    .Value(DateTime.Now) 
)

Before:
Before
After:
After

The link inserts midnight - but this feels wrong.

How do you make it insert the current time instead?


Update: Here is the DateTimePicker and javascript methods I used at the last step:

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var today = DateTime.Now.ToString("dd/MM/yyyy 00:00", 
                    new System.Globalization.CultureInfo("en-US"));
}


@(Html.Kendo().DateTimePicker()
    .Name("datetimer")
    .Animation(true)
    //.Culture("en-US")
    .TimeFormat("HH:mm")
    .Min(new DateTime(1900, 1, 1)) 
    .Max(new DateTime(2099, 12, 31)) 
    .Value(DateTime.Now)
    .Format("dd/MM/yyyy HH:mm")
    .Events(e => e.Change("datetimepicker_change"))
)


<script>
function datetimepicker_change() {
    // I use this method so that when selecting another day except from today, 
    // the hour should be 00:00. But it does not make sense whether or not using it 
    if ($('#datetimer').val() != '@today') {
        return;
    }


    if ($('#datetimer').val() == '@today') {
        $('#datetimer').val('@DateTime.Now.ToString("dd/MM/yyyy HH:mm")');
    }
}
</script>

Solution

  • Hello this is how i handle this;

    var today = DateTime.Now.ToString("dd/MM/yyyy 00:00", new System.Globalization.CultureInfo("en-US"));
    
    @(Html.Kendo().DateTimePicker()
        .Name("test")
        .Animation(true)
        .TimeFormat("HH:mm")
        .Min(new DateTime(1900, 1, 1))
        .Max(new DateTime(2099, 12, 31))
        .Value(DateTime.Now)
        .Format("dd/MM/yyyy HH:mm")
        .Events(e => e.Change("datetimepicker_change"))
     )
    
     <script>
      function datetimepicker_change() {
        if ($('#test').val() == '@today') {
            $('#test').val('@DateTime.Now');
        }
      }
     </script>
    

    full code via VS 2015

    result : youtube