php.mysql查询当天,查询本周,查询本月的数据实例(字段是时间戳) //其中 video 是表名: //createtime 是字段: // //数据库time字段为时间戳 // //查询当天: $start = date('Y-m-d 00:00:00'); $end = date('Y-m-d H:i:s'); SELECT * FROM `table_name` WHERE `time` >= unix_timestamp( '$start' ) AND `time` <= uni…
工作中遇到的问题,小结一下 查询今日添加的记录: select * from [表名] where datediff(day,CONVERT(VARCHAR(20),DATEADD(SECOND,[时间字段],'1970-01-01 00:00:00'),120),getdate())=0 这里的 CONVERT(VARCHAR(20),DATEADD(SECOND,[时间字段],'1970-01-01 00:00:00'),120) 是将时间戳(int)的时间字段转换为datetime类型.…
mysql 查询当天.本周,本月,上一个月的数据 今天 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(时间字段名) 近30天 SELECT * FROM 表…
SQL DATEDIFF语法及时间函数 Sql 查询当天.本周.本月记录 转:http://blog.csdn.net/Json1204/article/details/7863801?locationNum=11&fps=1 取某月天数:,) --当月天数 ,DATEADD(m, DATEDIFF(m,,getdate())+,))) ---当月第一天 ,getdate()) ---当月最后一天 ,dateadd(m,,dateadd(d,-day(getdate())+,getdate())…
mysql查询当天的所有信息: SELECT * FROM 表名 WHERE year(时间字段名)=year(now()) and month(时间字段名) = month(now()) and day(时间字段名) = day(now()); 这个有一些繁琐,还有简单的写法: SELECT * FROM 表名 WHERE date(时间字段名) = curdate(); 另一种写法没测试过 查询当天的记录 SELECT * FROM 表名 WHERE TO_DAYS(时间字段名) = TO_…
数据库字段是createtime 里面保存的是时间戳 <?php /* *按今天,本周,本月,本季度,本年,全部查询预约单数据 * $day 代表查询条件 $cid 代表 公司id *返回array $data 查询条件 数组 */ class ReserveModel extends BaseModel { public function find_createtime($day,$cid){ //查询当天数据 if($day==1){ $today=strtotime(date('Y-m-d…
查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 查询24小时内: select * from info where DateDiff(hh,datetime,getDate())<=24 查询当天: select * from table where DateDiff(dd,datetime,getdate())=0 本月记录 : SELECT * FROM 表 WHERE datediff(month,[date…
--查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info where DateDiff(hh,datetime,getDate())<=24 --info为表名,datetime为数据库中的字段值 --查询当天: select * from table where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: se…
--查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info where DateDiff(hh,datetime,getDate())<=24 --info为表名,datetime为数据库中的字段值 --查询当天: select * from table where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: se…
今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 近7天 DAY) <= date(时间字段名) 近30天 DAY) <= date(时间字段名) 本月 SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) 上一月 查询本季度数据 select * from `ht_invoice_informat…