If the month is the current month minus the time you want to calculate, for example, to query all records in the database for the first three months from today, our statement is as follows: mktime (date (\ 'H \ '), date (\' I \ '), date (\'s \'), date (\'m \ ')-3, date (\ 'd \ '), date (\ 'y \'); mktime (date (\ 'H \ ') within seven days \'), date (\ 'I \'), date (\'s \ '), date (\'m \'), date (\ 'd \ ')-7, date (\ 'y \'));
Mysql tutorial query specified date and time content SQL query statement
In the database tutorial design, you must note that the time field is preferably int (4). In this way, when saving in the database, it is a digital Date and Time cut, we can use the mktime function to find the time cut of the current date and add or subtract it. Let's look at the instance.
$ Time = time ();
// One month
$ LastMonth = mktime (date ('H'), date ('I'), date ('s'), date ('M')-1, date ('D'), date ('y '));
$ Where. = "dtime <$ lastMonth ";
// Three months
$ LastThreeMonth = mktime (date ('H'), date ('I'), date ('s'), date ('M')-3, date ('D'), date ('y '));
$ Where. = "dtime <$ lastThreeMonth ";
$ SQL = "select * from testtable". $ where
/*
The principle is:
If the month is the current month minus the time you want to calculate, for example, to query all records in the database for the first three months from today, our statement is as follows: mktime (date ('H'), date ('I'), date ('s'), date ('M')-3, date ('D '), date ('y '));
Within seven days: mktime (date ('H'), date ('I'), date ('s'), date ('M'), date ('D ') -7, date ('y '));
In an hour: mktime (date ('H')-1, date ('I'), date ('s'), date ('M '), date ('D'), date ('y '));
Other methods are the same.
Source www. bKjia. c0m
*/