There is a table TOS_MES, it has the fields MONTH_CH and YEAR_CH, in the template there are 2 input fields with type = 'month' (date from and to). How to display all data from this table on the dates that the user specified in these fields? I tried to do it through whereBetween, but it does not work correctly, namely if I, for example, choose the 6th month and the 2017th year and until the 11th month of the 2018th, it will only output data from 6-11 months. I tried to bring this data into Unix-time, but in this case nothing is output at all. Date in Yn format:

$newDateFrom = explode("-", $data['dateFrom']); // Дата от $newDateTo = explode("-", $data['dateTo']); // Дата до $dataForTable = DB::table('CAT_STATION') ->join('CAT_OBL', 'CAT_STATION.OBL_ID', '=', 'CAT_OBL.OBL_ID') ->join('TOS_MES', 'CAT_STATION.IND_ST', '=', 'TOS_MES.IND_ST') ->select('CAT_OBL.NAME_OBL', 'CAT_STATION.NAME_ST', 'TOS_MES.IND_ST', 'TOS_MES.YEAR_CH', 'TOS_MES.MONTH_CH', 'TOS_MES.T', 'TOS_MES.OS') ->orderBy('CAT_STATION.OBL_ID', 'asc') ->orderBy('CAT_STATION.IND_ST') ->whereIn('CAT_STATION.OBL_ID', $data['regionName']) ->whereBetween('YEAR_CH', [$newDateFrom[0], $newDateTo[0]]) ->whereBetween('MONTH_CH', [$newDateFrom[1], $newDateTo[1]]) ->get(); 
  • Collect the year and month of the filter as strings together according to the YYYYMM pattern, and select the usual BETWEEN with the same expression from the table fields. if I, for example, choose the 6th month and the 2017th year and the 11th month of the 2018th, then you will search from 201706 to 201811. - Akina
  • The input field returns me a yyyy-MM format string and the query works, but not correctly, because then it does not display me a month before the 6th and after the 11th - zolotoi2012
  • Are the table fields in the same format collected? - Akina
  • Table fields - int - zolotoi2012
  • O! Well, so they also need to be converted to string, moreover with the leading zero for the month, and converted into the same format that comes from the filter. Or vice versa, to turn everything (both fields and filter conditions) into numbers - not forgetting to multiply the year by 12 ... - Akina

0