In the database tutorial design, you must note that the Time field is int (11) So, the database is saved in a numeric date time stamp, we can use the Mktime function to find the current date of time stamp to add and subtract is OK, see the example below
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
/*
principle is:
If the month is the current month minus the time you want to count, as I'm querying the database for all records from today onwards for three months, our statement is as follows: Mktime (' 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 '));
Within one 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 ') -1,01,date (' Y '));
Last Last day: Mktime (0,0,0,date (' m '), 0,date (' y '));
First day of the month: This is simple, that is, 01;
Last day of the month: This uses the DATE function, the DATE function has a parameter T, it is used for the last day, for example: Date (' t ')
The other approach is the same.
http://www.bkjia.com/PHPjc/326224.html www.bkjia.com true http://www.bkjia.com/PHPjc/326224.html techarticle you must pay attention to the time field in the Database tutorial design int (11) So, the database is saved in a numeric date time stamp, we can use the Mktime function to find the current date timestamp ...