Changing a date value of Kendo DatePicker or Jquery full date string format

1.6k views Asked by At

I currently have a Kendo DatePicker in my grid. The format I use is MM/yyyy. I don't need to select a Day. But in DB, when I select dates and hit the save changes button, the DatePicker chooses a Day as "1", and the DB inserts that value. So For example, if I select 9/2020 from the UI and submit, in DB, the value will be 2020-09-01.

So now the problem is, I have another Date Picker search filter outside of the grid. When I select a date, for example, 9/2020, it searches for "2020-09-[Today's Day]" in stead of "2020-09-01". So it will just return nothing even if I just inserted 09/20 data.

Date Picker that I'm using as a search feature:

    $('#searchBoxDate').kendoDatePicker({
        start: "year",
        depth: "year",
        min: new Date(2000, 01, 01),
        format: "{0:MM/yyyy}"
    });

My question is --

  1. Is there a way to make #searchBoxDate automatically select a Day as "1" when I select Year and Month?

OR

  1. Is there a way to change the Day "18" to "1" in a full string format? Sun Oct 18 2020 01:39:28 GMT-0400 (Eastern Daylight Time)
1

There are 1 answers

0
CMartins On

Add a change function to the onChange event to always correct the date to the first day of the month:

change: function() {
      var value = this.value();
      var days = value.getDate();
      var d = new Date();
      d = value;
      d.setDate(d.getDate()-days+1);
        console.log(d); 
    }