sql语句获取本周、上一周、本月数据

获取周数据

1 本周
2 select * from table1 where datediff(week,时间字段,getdate()) = 0
3 上周
4 select * from table1 where datediff(week,时间字段,getdate()) = 1
5 下周
6 select * from table1 where datediff(week,时间字段,getdate()) = -1

获取月数据

1 本月
2 select * from table1 where datediff(mm,时间字段,getdate()) = 0
3 上月
4 select * from table1 where datediff(mm,时间字段,getdate()) = 1
5 下月
6 select * from table1 where datediff(mm,时间字段,getdate()) = -1

昨天:

dateadd(day,-1,getdate())

明天:

dateadd(day,1,getdate())

上月:

month(dateadd(month,-1,getdate()))

本月:

month(getdate())

下月:

month(dateadd(month,1,getdate()))

昨天:

select * from table1 where datediff(dd,时间字段,getdate()) = 1

明天:

select * from table1 where datediff(dd,getdate(),时间字段) = -1

最近七天:

select * from table1 where datediff(dd,时间字段,getdate()) <= 7

当前年:

select 提出日期,datepart(year,getdate()) as 当前年 from table1

前一年:

select 提出日期,datepart(year,getdate()) -1 as 当前年 from table1

后一年:

select 提出日期,datepart(year,getdate()) +1 as 当前年 from table1

Sqlserver语句获取本周、上一周、本月数据的更多相关文章

  1. js 获取 本周、上周、本月、上月、本季度、上季度的开始结束日期

    js 获取 本周.上周.本月.上月.本季度.上季度的开始结束日期 /**  * 获取本周.本季度.本月.上月的开始日期.结束日期  */ var now = new Date(); //当前日期 va ...

  2. C#获取本周、上周、本月、上月、本季度、上季度、本年、上一年起始时间和结束时间

    /// 取得某月的第一天 /// </summary> /// <param name="datetime">要取得月份第一天的时间</param&g ...

  3. sql语句获取本周、本月、本年数据

    本周:select * from table where datediff(week,C_CALLTIME,getdate())=0     --C_CALLTIME 为日期字段本月:select * ...

  4. java获取当前上一周、上一月、上一年的时间

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = Calend ...

  5. SQL获取本周,上周,本月,上月第一天和最后一天[注:本周从周一到周天]

    DECLARE @ThisWeekStartTime NVARCHAR(100),@ThisWeekEndTime NVARCHAR(100),--本周 @LastWeekStartTime NVAR ...

  6. SQL获取本周,上周,本月,上月的开始时间和结束时间

    ),),--本周 ),),--上周 ),),--本月 ),),--上月 ),),--近半年 ),)--近一年 ), ,, ),)--本周开始时间 ), ,, ),)--本周结束时间 ),,, ),)- ...

  7. PHP 获取本周、今日、本月的起始时间戳

    当前周的开始时间(周一)$begintime = mktime(0, 0, 0, date('m'), (date('d') - (date('w')>0 ? date('w') : 7) + ...

  8. SQLSERVER 触发器 将一个服务器上的数据库中数据插入到另一个服务器上的数据库中怎么做

    首先要执行 sp_addlinkedserver '服务器ip' 然后开始写语句 insert into ip.库名字.dbo.table select * from iserted

  9. 用IHTMLDocument2接口获取页面上想要的数据,代替正则表达式

    原文发布时间为:2010-07-01 -- 来源于本人的百度文章 [由搬家工具导入] 1. 用 IHTMLDocument2::all 获得所有元素; 2. 用 IHTMLElementCollect ...

随机推荐

  1. 794. Valid Tic-Tac-Toe State

    A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...

  2. 指定pdf的格式

    爬虫实战[3]Python-如何将html转化为pdf(PdfKit)   前言 前面我们对博客园的文章进行了爬取,结果比较令人满意,可以一下子下载某个博主的所有文章了.但是,我们获取的只有文章中的文 ...

  3. hdu3715 二分+2sat+建图

    题意:       给你一个递归公式,每多一层就多一个限制,问你最多能递归多少层. 思路:      先分析每一层的限制 x[a[i]] + x[b[i]] != c[i],这里面x[] = 0,1, ...

  4. UVA11020 优势人群(multiset)

    题意:       给你N个人,每个人有两个权值,x,y对于某一个人,如果不存在某一个人x' y', x' < x && y' <= y 或者x' <= x & ...

  5. Intel汇编程序设计-整数算术指令(中)

    7.3  移位和循环移位的应用 7.3.1  多双字移位 要对扩展精度整数(长整数)进行移位操作,可把它划分为字节数组.字数组或双字数组,然后再对该数组进行移位操作.在内存中存储数字时通常采用的方式是 ...

  6. UA: Literally Vulnerable靶机

    前言 略有点虎头蛇尾.主要有一步没想通. web打点 nmap -sP 192.168.218.0/24 #发现主机IP 192.168.218.138 #端口扫描 nmap -sV -p- 192. ...

  7. nginx日志文件按天记录定时清理循环记录

    问题 nginx日志默认记录在一个文件access.log中,时间长了会导致日志文件特别大,甚至磁盘占满. 解决方案 使用以下方法,将access.log文件每天一个,然后清过15天以前的文件. 方法 ...

  8. SE_Work4_软件案例分析

    项目 内容 课程:北航-2020-春-软件工程 博客园班级博客 要求:分析软件案例 个人博客作业-软件案例分析 班级 005 这个作业在哪个具体方面帮助我实现目标 分析对比一类软件,学会规划分析软件的 ...

  9. 普里姆算法(Prim)邻接矩阵法

    算法代码 C#代码 using System; namespace Prim { class Program { static void Main(string[] args) { int numbe ...

  10. [项目] 淘淘商城 Part.2

    商品列表查询 Easyui 商品添加 商品类目选择 图片上传 富文本编辑器使用 添加的实现 展示首页 略 分页插件 在SqlMapConfig.xml,配置一个plugin 在sql语句执行之前,添加 ...