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
CopyCode The Code is as follows: $ lastmonth = mktime (date ('H'), date ('I'), date ('s'), date ('M')-1, date ('D'), date ('y '));
$ Where. = "dtime> $ lastmonth ";
// Three monthsCopy 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
/*
principle :
If the month is the current month minus the time you want to calculate, for example, if I want to query all the records in the database from the past three months from today, our statement is as follows: mktime (date ('H'), date ('I'), date ('s'), date ('M')-3, date ('D '), date ('y');
in the past 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, 0, 0, date ('M ')-, Date ('y');
last day of last month: mktime (, 0, date ('M'), 0, date ('y '));
day 1 of this month: This is simple, that is, 01.
last day of this month: the date function is used. The date function has a parameter t, it is used to calculate the last day. For example, date ('T')
The same applies to other methods.