Sql Server中查询今天、昨天、本周、上周、本月、上月数据
来源:互联网 发布:英文原著推荐 知乎 编辑:程序博客网 时间:2024/04/28 18:45
在做Sql Server开发的时候有时需要获取表中今天、昨天、本周、上周、本月、上月等数据,这时候就需要使用DATEDIFF()函数及GetDate()函数了。
DATEDIFF ( datepart , startdate , enddate )
释义:计算时间差
datepare值:year | quarter | month | week | day | hour | minute | second | millisecond
startdate:开始日期
enddate :结束日期
GetDate()
释义:获取当前的系统日期
下面例子中表名为tablename,条件字段名为inputdate
查询今天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=0
查询昨天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=1
查询本周
SELECT * FROM tablename where datediff(week,inputdate,getdate())=0
查询上周
SELECT * FROM tablename where datediff(week,inputdate,getdate())=1
查询本月
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=0
查询上月
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=1
转载地址:https://www.douban.com/note/508175036/
DATEDIFF ( datepart , startdate , enddate )
释义:计算时间差
datepare值:year | quarter | month | week | day | hour | minute | second | millisecond
startdate:开始日期
enddate :结束日期
GetDate()
释义:获取当前的系统日期
下面例子中表名为tablename,条件字段名为inputdate
查询今天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=0
查询昨天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=1
查询本周
SELECT * FROM tablename where datediff(week,inputdate,getdate())=0
查询上周
SELECT * FROM tablename where datediff(week,inputdate,getdate())=1
查询本月
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=0
查询上月
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=1
转载地址:https://www.douban.com/note/508175036/
0 0
- Sql Server中查询今天、昨天、本周、上周、本月、上月数据
- Sql Server中查询今天、昨天、本周、上周、本月、上月数据
- Sql Server中查询今天、昨天、本周、上周、本月、上月数据
- Sql Server 获取表中今天、昨天、本周、上周、本月、上月等数据
- sqlserver查询今天、昨天、本周、上周、本月、上月等数据
- 查询今天、昨天、本周、上周、本月、上月数据
- sql时间查询上周 本周 上月 本月
- php显示日期(今天、昨天、本周、上周、本月、上月、)
- mysql 查询当天、昨天、本周、上周、本月、上月、今年、去年数据
- mysql 查询当天、昨天、本周、上周、本月、上月、今年、去年数据
- sql语名查询"今天","昨天","本周","本月"数据方法!
- C# 昨天今天明天上周本周下周上月本月下月等日期计算
- 时间:今天、昨天、本周、上周、本月、上月、本季度、上季度、今年、去年
- 求当天,昨天,本周,上周,本月,上月的函数
- mysql 查询今天、昨天、上月、本月的数据
- mysql 数据库查询今天、昨天、上月、本月的数据
- mysql 查询今天、昨天、上月、本月的数据
- mysql 查询今天、昨天、上月、本月的数据
- 260. Single Number III
- java乱码深入分析
- iOS项目的本地化处理(多国语言)
- Oracle 查询今天、昨日、本周、本月和本季度的所有记录
- DXGI——DirectX Graphics Infrastructure
- Sql Server中查询今天、昨天、本周、上周、本月、上月数据
- 十年了,Hadoop的前世今生
- 函数形参的传递
- js 图片滚动
- 信号与信号量的区别
- 《合成孔径雷达成像——算法与实现》之【8】仿真图3.8
- Android_Service组件详解
- 赛码网常见接受参数的方法
- 数位板的主要参数解析