thinkphp Query Day, this week, this month, this quarter, this year, all, data method

Source: Internet
Author: User

<?php
/*
* By today, this week, this month, this quarter, this year, all query the reservation form data
* $day representative query criteria $cid on behalf of the company ID
* Returns array $data query criteria
*/
Class Reservemodel extends Basemodel {
Public Function Find_createtime ($day, $cid) {
Query Day Data
if ($day ==1) {
$today =strtotime (Date (' y-m-d 00:00:00 '));
$data [' CID ']= $cid;
$data [' createtime '] = Array (' Egt ', $today);
return $data;
Query this week's data
}else if ($day ==2) {
$arr =array ();
$arr =getdate ();
$num = $arr [' wday '];
$start =time ()-($num-1) *24*60*60;
$end =time () + (7-$num) *24*60*60;
$data [' CID ']= $cid;
$data [' createtime '] = Array (' Between ', Array ($start, $end));
return $data;
Query this month's data
}else if ($day ==3) {
$start =strtotime (Date (' y-m-01 00:00:00 '));
$end = strtotime (Date (' y-m-d h:i:s '));
$data [' CID ']= $cid;
$data [' createtime '] = Array (' Between ', Array ($start, $end));
return $data;
Query this quarterly data
}else if ($day ==4) {
$month =date (' m ');
if ($month ==1 | | $month ==2 | | $month ==3) {
$start =strtotime (Date (' y-01-01 00:00:00 '));
$end =strtotime (Date ("y-03-31 23:59:59"));
}elseif ($month ==4 | | $month ==5 | | $month ==6) {
$start =strtotime (Date (' y-04-01 00:00:00 '));
$end =strtotime (Date ("y-06-30 23:59:59"));
}elseif ($month ==7 | | $month ==8 | | $month ==9) {
$start =strtotime (Date (' y-07-01 00:00:00 '));
$end =strtotime (Date ("y-09-30 23:59:59"));
}else{
$start =strtotime (Date (' y-10-01 00:00:00 '));
$end =strtotime (Date ("y-12-31 23:59:59"));
}
$data [' CID ']= $cid;
$data [' createtime '] = Array (' Between ', Array ($start, $end));
return $data;
Query this year's data
}else if ($day ==5) {
$year =strtotime (Date (' y-01-01 00:00:00 '));
$data [' CID ']= $cid;
$data [' createtime '] = Array (' Egt ', $year);
return $data;
All data
}else{
$data [' CID ']= $cid;
return $data;
}
}
}
?>

And then write in CompanyAction.class.php.

$list = $Shop->where ($data)->select ();

$this->list= $list;

$this->display ();

The data is found out ...

thinkphp Query Day, this week, this month, this quarter, this year, all, data method

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.