使用日期功能搜索内容

时间:2014-08-18 12:46:27

标签: php mysql

通过使用此功能,我必须按日期搜索数据库中的某些内容。这种编码效果很好。但我不想爆炸它。这可能只使用strtotome()而不是爆炸来按日期搜索记录吗?

function doSelectBranchRecords($objArray)
        {
            $strWhereClause = '';
            if ($objArray['frmNameSearch']) {
                $strWhereClause.= " AND A.branch_ident = '".$objArray['frmNameSearch']."' ";
            }
            if ($objArray['frmLoanSearch']) {
                $strWhereClause.= " AND A.loan_ident LIKE '%".$objArray['frmLoanSearch']."%' ";
            }
            if ($objArray['frmBeneficiarySearch']) {
                $strWhereClause.= " AND A.beneficiary_idents LIKE '%".$objArray['frmBeneficiarySearch']."%' ";
            }
            if ($objArray['frmDateSearch']) {

                $strDate = explode("-", $objArray['frmDateSearch']);
                $strAccountstarted = $strDate[2].'-'.$strDate[1].'-'.$strDate[0];

                $strWhereClause.= " AND A.account_started = '".$strAccountstarted."' ";
            }

        $strSqlSelect = "SELECT A.*, B.branch_name FROM tbl_companydetails as A,tbl_branchdetails as B where A.branch_ident = B.branch_id $strWhereClause order by company_id DESC";
        $strValues = SelectQry($strSqlSelect);
        return $strValues;
    }

1 个答案:

答案 0 :(得分:0)

尝试替换

$strDate = explode("-", $objArray['frmDateSearch']);
$strAccountstarted = $strDate[2].'-'.$strDate[1].'-'.$strDate[0];

$strAccountstarted = date('Y-m-d H:i:s', strtotime($objArray['frmDateSearch']));

如果您不需要时间,请从日期删除H:i:s