问题
I have this table
training_schedules
- id
- course_reference
- start_date(date)
- end_date(date)
- year_id(int, fk)
on my form, I have dropdownlist for the month, and another one for the year.
Now as you can see there is a mismatch on the month from form
and database column
. How can I filter the start_date
or end_date
column using only the integer value from the dropdownlist and ignore the day
and year
part of the db column?
I saw some examples but using raw query and using date functions of database which is not good if you consider performance because it is not indexable.
Can I achieve this using Eloquent/Fluent Api of Laravel?
回答1:
If you are using mysql u can use the month() function to get month from date
For further clarification please visit the link
来源:https://stackoverflow.com/questions/22470657/how-to-query-only-by-month-on-date-input-and-ignore-the-year-and-day-considering