from_unixtime查询某年或某月的数据
发表于:2023-09-09 16:20:45浏览:87次
1.语法
from_unixtime(timestamp ,date_format)
参数:
timestamp :时间戳,可为一串数字,也可为字段。
10位数
date_format:时间格式,不填默认为%Y-%m-%d %H:%i:%s的格式。
2.实例
select ID,name,from_unixtime((timestamp + 8*3600),"%Y%-m-%d") as date
from product
where from_unixtime((timestamp + 8*3600),"%Y-%m-%d")>='2020-02-01'
或
select ID,name,from_unixtime((timestamp + 8*3600),"%Y-%m-%d %H:%i:%s") as date
from product
where from_unixtime((timestamp + 8*3600),"%Y-%m-%d")>='2020-02-01'
或
select ID,name,from_unixtime((timestamp + 8*3600),"yyyyMMdd") as date
from product
where from_unixtime((timestamp + 8*3600),"yyyy-MM-dd")>='2020-02-01'
3.thinkphp 实例 搜索某月或某年的数据
$tongji_str = $tongji['year'].'-'.$tongji['month'];
$tongji_res_list = Db::query('SELECT * FROM fa_renwu WHERE
FROM_UNIXTIME(uploadtime,"%Y-%m")="'.$tongji_str.'"');
$tongji_str = $tongji['year'];
$tongji_res_list = Db::query('SELECT * FROM fa_renwu WHERE
FROM_UNIXTIME(uploadtime,"%Y")="'.$tongji_str.'"');
注意:$tongji_str示例为:"2022-11","2020-05",小于10月份的注意要添加0
栏目分类全部>