Mysql queries the implementation principle and code of SQL statements within a specified date. When designing a database tutorial, you must note that the time field is int (11). In this way, a digital date timestamp is stored in the database, we can use the mktime function to find the timestamp of the current date. in the database tutorial design, we must note that the time field is int (11). In this way, a digital date timestamp is saved in the database, we can use the mktime function to find the timestamp of the current date and add or subtract it. The following figure shows the instance.
// One month
The code is as follows:
$ LastMonth = mktime (date ('h'), date ('I'), date ('s'), date ('M')-1, date ('D'), date ('Y '));
$ Where. = "dtime> $ lastMonth ";
// Three months
The code is as follows:
$ 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 '));
First day of last month: mktime (, 0, date ('M')-, date ('Y '));
Last day of last month: mktime (0, 0, 0, date ('M'), 0, date ('Y '));
The first day of this month: this is simple, that is, 01;
Last day of the month: this requires the date function. the date function has a parameter t, which is used to calculate the last day. for example, date ('t ')
Other methods are the same.
In this case, the database stores a digital date timestamp. we can use the mktime function to find the timestamp of the current date...