资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php查询一年之前的数据,php查询数据是否存在

thinkphp中如何查询当天,本周的,本月的,本年的数据,

//当天时间

创新互联主要从事成都网站设计、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务海珠,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

$where['time'] = array(

array('egt',strtotime(date('Y-m-d',time())),

array('lt',strtotime(date('Y-m-d',time())).'+1 day')

);

// 本周时间

$where['time'] = array(

array('egt',strtotime(date('Y-m-d',time())).'-'.date('w',time()).' day'),

array('lt',strtotime(date('Y-m-d',time())).'+1 week -'.date('w',time()).' day');

);

// 本月时间

$where['time'] = array(

array('egt',strtotime(date('Y-m',time()))),

array('lt',strtotime(date('Y-m',time()).'+1 month'))

);

// 本年时间

$where['time'] = array(

array('egt',strtotime(date('Y',time()))),

array('lt',strtotime(date('Y',time()).'+1 year'))

);

上面是查询条件,直接运用到查询语句就可以了

$result = $db-where($where)-select();

更正下上面的那个 本年 查询时间

$where['time'] = array(

array('egt',strtotime(date('Y-01-01',time())),

array('lt',strtotime(date('Y-01-01',time()).'+1 year'))

);

如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢

/*今天*/

select * from 表名 where to_days(时间字段) = to_days(now());

/*昨天*/

select * from 表名 where to_days(now())-to_days(时间字段) = 1;

/*近7天*/

select * from 表名 where date_sub(curdate(), interval 7 day) = date(时间字段);

/*查询距离当前现在6个月的数据*/

select * from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();

/*查询当前这周的数据*/

select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());

/*查询上周的数据*/

select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;

/*查询当前月份的数据*/

select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');

/*查询上个月的数据*/

select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');

其它获取类似以上的代码显示

php中如何查询指定时间段的数据?

下面是时间戳查询。如果数据库时间显示的是 2011-04-05 那就不需要 用 strtotime 时间戳转换函数:

$timea = strtotime($_POST['timea']);

$timeb = strtotime($_POST['timeb']);

$sq2="select * from `ecs_order_info` where add_time between '$timea' and '$timeb' and `quanxian`='$dangqian' order by `order_id` DESC limit 50";

$sql = mysql_query($sq2);

扩展资料

在php中完成

1、UNIX时间戳转换为日期用函数: date()

一般形式:date('Y-m-d H:i:s', 1156219870);

2、日期转换为UNIX时间戳用函数:strtotime()

一般形式:strtotime('2010-03-24 08:15:42');

在MySQL中完成

这种方式在MySQL查询语句中转换,优点是不占用PHP解析器的解析时间,速度快,缺点是只能用在数据库查询中,有局限性。

1、UNIX时间戳转换为日期用函数: FROM_UNIXTIME()

一般形式:select FROM_UNIXTIME(1156219870);

2、日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP()

一般形式:Select UNIX_TIMESTAMP('2006-11-04 12:23:00′);

举例:mysql查询当天的记录数:

$sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') order by id desc”。


标题名称:php查询一年之前的数据,php查询数据是否存在
标题链接:http://cdkjz.cn/article/hseess.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220