【sql server数据库】
1、时间转为字符串
2、查询昨天,也是时间格式转为字符串格式
3、所以七天内的数据查询条件,字符串格式再转为时间格式
select *
from mytable
where
convert(datetime,convert(varchar(10),timefield,120),120)>
convert(datetime,convert(varchar(10),dateadd(day,-7,getdate()),120),120)
and
convert(datetime,convert(varchar(10),timefield,120),120)<=
convert(datetime,convert(varchar(10),getdate(),120),120)
order by timefield desc
4、时间格式化:yyyy-MM-dd
select convert(varchar(10),GETDATE(),120)
5、时间格式化:yyyy-MM-dd HH:mm:ss
select convert(varchar(50),GETDATE(),120)