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 and add or subtract it. The following figure shows the instance.
// One month
Copy codeThe Code is as follows:
$ LastMonth = mktime (date ('H'), date ('I'), date ('s'), date ('M')-1, date ('D'), date ('y '));
$ Where. = "dtime> $ lastMonth ";
// Three months
Copy codeThe 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.