There is a table
enter image description here
When I insert a record (from the application / client), I fill in the "date" field.
Question :
Is it possible to automat (on the server side) somehow fill in the "year_month" field (type INT), after filling in the "date"? if this field should display “month” and “year” (entered in “date”), if this does not trigger this. Or it should be done by the client.

Thank.

  • one
    This field in the database is not needed at all. because its value can always be calculated using DATE_FORMAT on the MySQL side and showing - Mike
  • I know ... there are still functions "year" and "month" (for a breakdown by year and month). I need the “year_month” field to display the data on the “Archive” page, where only “year” and “month” are displayed, and then it is easier to sample (for display) data for the month, Ie the corresponding link to do on the page - Konstantin78
  • one
    And the worse select *, DATE_FORMAT(date,'%m%Y') as year_month from table , than just select * . In the end, you can do the view: create view MyView as select *, DATE_FORMAT(date,'%m%Y') as year_month from table is this column really on the table - Mike
  • C view is good, but I work with the framework, and I didn’t really want to form the selection condition in view (html). And so I already have a formed array, which I output in html, the element of which is “year” and “month”, and which (if anything happens) I pass in the address bar to get a period of one month, for example “201608” - articles for august 2016 - Konstantin78
  • By creating an extra column, you denormalize the database. view in this case is the database view. - Ponio

0