Retrieve data from the database the data of the previous week, that is, the data of the previous week in this week, and the data of the previous week in the next week. how can we get the data? the specified date range is enough. & lt ;? PhpfunctiongetLastWeekDate ($ date) {$ iDate = strtotime ($ date); $ iLastDate = $ iDate get data
Retrieve data from the database from the last week, that is, the data from the last week, and the data from the last week. how can this data be obtained from the database?
------ Solution --------------------
The specified date range is enough.
------ Solution --------------------
Function getLastWeekDate ($ date ){
$ IDate = strtotime ($ date );
$ ILastDate = $ iDate-7 * 24*60*60;
If (date ('W', $ iLastDate) = 0) {// Sunday
$ SLastWeekStart = date ('Y-m-d 00:00:00 ', $ iLastDate-7 * 24*60*60 );
$ SLastWeekEnd = date ('Y-m-d 23:59:59 ', $ iLastDate );
} Else {// non-Sunday
$ SLastWeekStart = date ('Y-m-d 00:00:00 ', $ iLastDate-date ('W', $ iLastDate) * 24*60*60 );
$ SLastWeekEnd = date ('Y-m-d 23:59:59 ', $ iLastDate + (7-date ('W', $ iLastDate) * 24*60*60 );
}
Return array ('start _ time' => $ sLastWeekStart, 'end _ time' => $ sLastWeekEnd );
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service