sql |
您所在的位置:网站首页 › sql获取一年前的日期和时间 › sql |
sql–sqlsever–时间相关SQL语句–查询当前时间至前N天的数据
. . . sql server:取当前时间前10分钟之内的数据 dateadd()当前时间 select GETDATE()当前时间点前10分钟 dateadd() select dateadd(minute,-10,GETDATE())取当前时间点前10分钟以内的数据,且按创建时间倒序排 select * from tablename where CreateDate > dateadd(minute,-10,GETDATE()) order by CreateDate descdateadd(间隔类型,增量,时间点) select DATEADD(year,-1,getdate()) --一年前 select DATEADD(MONTH,6,getdate()) --+6个月时间点 select DATEADD(WEEK,1,getdate()) --一周 select DATEADD(DAY,2,getdate()) -- 2天 select DATEADD(HOUR,12,getdate()) --12小时 select DATEADD(SECOND,30,getdate()) -- 30秒原文:http://www.mamicode.com/info-detail-2526260.html 1、查询前30天的数据,如果DateTime为字符串型,则需要将getdate()获取到的日期型通过convert转换为字符串型(查询前五天则将30改成5): select * from table where DateTime>CONVERT(varchar(100), dateadd(day,-30,GETDATE()), 112) 用sql查询当天,一周,一个月的数据 数据查询,不管在网站还是在系统,都很常见,下文是介绍最常见的以日期查询的语句 select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0 //查询当天日期在一周年的数据 select * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 //查询当天的所有数据 –查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 –查询24小时内的: select * from info where DateDiff(hh,datetime,getDate()) |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |