I would like to filter out old records and present only newer ones. The idea is currentDate minus 2 years. One record looks like this (table Symposium):
Attributes:
ID;Day;Month;Year;Firstname;Lastname;Symposium_title;Speakers;
Records
1;26;10;2012;Markus;Meier;Topic MySQL;5;
3;26;10;2011;Markus;Meier;Topic PHP;5;
6;26;01;2010;Markus;Meier;Topic CSS;5;
Wished output
1;26;10;2012;Markus;Meier;Topic MySQL;5;
3;26;10;2011;Markus;Meier;Topic PHP;5;
I could easily do a small php to filter out older data, but I’m sure there is a way to do it direct with mysql in one command.
some query like this (this is just pseudo code)
SELECT * FROM Symposium WHERE (current_data() - 2 Years);
remark: The attributes day;month;year will not be changed. There are more then 50 tables, that are build up by this attributes. So don’t recommend change of the table.
Can someone help me ?
You can use STR_TO_DATE function and DATE_ADD for this task:
syntax:
So in your code:
(sadly, I don’t have a MySQL at hand right now, so I can’t test it, but unless there is some very basic typo in it, it should work)