TP3 根据时间区间搜索的方法

/**
 * 时间段查询条件获取
 * @param string $star  获取开始时间的字段名
 * @param string $end   获取结束时间的字段名 
 * @param string $zd    数据库where条件的字段名
 */
function where_time($start='start_time',$end='end_time',$zd='create_time'){
    $start_time=I('get.'.$start,'','filter_str');
    $end_time=I('get.'.$end,'','filter_str');
    $map = array();
    if(!empty($start_time)){
        $start_time=strtotime($start_time);
        $map[$zd] = array('gt',$start_time);
    }
    
    if(!empty($end_time)){
        $end_time=strtotime($end_time);
        if(empty($map[$zd])){
            $map[$zd] = array('lt',$end_time);
        }else{
            $map[$zd]=array($map[$zd],array('lt',$end_time));
        }
    }
    return $map;
}

 
原文地址:https://www.cnblogs.com/phpwyl/p/9836692.html