今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0

昨天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=1

7天内的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=7

30天内的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=30

本月的所有数据:select * from 表名 where DateDiff(mm,datetime类型字段,getdate())=0

本年的所有数据:select * from 表名 where DateDiff(yy,datetime类型字段,getdate())=0

查询今天是今年的第几天: select datepart(dayofyear,getDate())

查询今天是本月的第几天:1. select datepart(dd, getDate())

2.select day(getDate())

查询本周的星期一日期是多少 (注意:指定日期不能是周日,如果是周日会计算到下周一去。所以如果是周日要减一天) SELECT DATEADD(wk,DATEDIFF(wk,0,getdate()),0)

查询昨天日期:select convert(char,dateadd(DD,-1,getdate()),111)  //111是样式号,(100-114)

查询本月第一天日期:Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) as firstday

查询本月最后一天日期:Select dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0)) as lastday      //修改-3的值会有相应的变化

本月有多少天:select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast((cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' ) as datetime ))))

求两个时间段相差几天:select datediff(day,'2012/8/1','2012/8/20') as daysum

在指定的日期上±N天:select convert(char,dateadd(dd,1,'2012/8/20'),111) as riqi    //输出2012/8/21

在指定的日期上±N分钟:select dateadd(mi,-15,getdate())  //查询当前时间15分钟之前的日期

Sql日期查询-SQL查询今天、昨天、7天内、30天的更多相关文章

  1. Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等)

    Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等) 子查询 描述:查询订单数超过5的顾客信息 查询句法: var 子查询 = from c i ...

  2. SQL Server T-SQL高级查询

    name like 'ja%'; select * from student where name not like '%[j,n]%'; select * from student where na ...

  3. 【转】SQL Server T-SQL高级查询

    SQL Server T-SQL高级查询 高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; //查询student ...

  4. SQL Server T-SQL高级查询(转)

    高级查询在数据库中用得是最频繁的,也是应用最广泛的.   Ø 基本常用查询   --select select * from student; --all 查询所有 select all sex fr ...

  5. util-C# 复杂条件查询(sql 复杂条件查询)查询解决方案

    ylbtech-funcation-util:  C# 复杂条件查询(sql 复杂条件查询)查询解决方案 C# 复杂条件查询(sql 复杂条件查询)查询解决方案 1.A,Ylbtech.Model返回 ...

  6. oracle 基础SQL语句 多表查询 子查询 分页查询 合并查询 分组查询 group by having order by

    select语句学习 . 创建表 create table user(user varchar2(20), id int); . 查看执行某条命令花费的时间 set timing on: . 查看表的 ...

  7. SQL Server T-SQL高级查询【转】

    高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student;   --all 查询所有 select all sex from ...

  8. SQL Server T-SQL高级查询1

    高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student;   --all 查询所有 select all sex from ...

  9. sql like 通配符 模糊查询技巧及特殊字符

    最近碰到like模糊匹配的问题,找到一些答案接触迷惑,觉得有知识是自己忽略的,现在整理出来,既强化记忆,又是一次记录,以下转自一篇Blog,关于sql server like的通配符和字符带通配符的处 ...

  10. SQL Server 基础 03 查询数据基础

    查询数据 简单的查询 create table stu_info ( sno int not null ,sname ) not null ,sex ) not null ,birth ) not n ...

随机推荐

  1. python 安装离线库

    (起因:报错找不到一个module,百度也找不到这个module,机智如我找宁博翻墙看怎么解决,毕竟是歪果仁的代码嘛,果真就在git找到了这个module哈哈哈哈机智如我!) 方法: 进入命令行窗口, ...

  2. JavaScript中的内存溢出与内存泄漏

    内存溢出 是一种程序运行出现的错误: 当程序运行需要的内存超过了剩余的内存时, 就出抛出内存溢出的错误 var obj = {} for (var i = 0; i < 100000; i++) ...

  3. 什么是Java内存模型

    转载 : https://www.jianshu.com/p/bf158fbb2432 在知识星球中,有个小伙伴提了一个问题: 有一个关于JVM名词定义的问题,说”JVM内存模型“,有人会说是关于JV ...

  4. compass和paoding分词器的基本使用

    1.实现搜索的技术: 数据库查询:like查询:lucene全文检索技术: 1)在数据量比较大,查询字段比较多的情况下,如果采用数据库like sql查询,性能比较差:采用lucene来查询,性能相对 ...

  5. Ubuntu系统之Hadoop搭建

    作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3223 一.在Window中安装Oracle VM VirtualBox 二 ...

  6. 第07组 Beta冲刺(5/5)

    队名:摇光 队长:杨明哲 组长博客:求戳 作业博客:求再戳 队长:杨明哲 过去两天完成了哪些任务 文字/口头描述:暂时没有. 展示GitHub当日代码/文档签入记录:(组内共用,已询问过助教小姐姐) ...

  7. bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

    工程中引入其他工程的包,由于两个工程中有重名的两个bean,导致在启动时提示如下错误: 根据bean名称在ide中查找,找到这两个重名的类,可以看到由于这两个类使用@Service标注,此时如果不使用 ...

  8. 生成Nginx服务器SSL证书和客户端证书

    Nginx服务器SSL证书 生成pass key 下面的命令用于生成一个2048bit的pass key, -passout pass:111111 用于避免交互式输入密码 [tomcat@a02 t ...

  9. 以太坊公链Geth同步

    1.安装所需基础工具 yum update -y && yum install git wget bzip2 vim gcc-c++ ntp epel-release nodejs c ...

  10. 025批量删除mac文件名中的空格

    一. 在准备王陆语料库资料时发现给的录音文件好多带有空格,不喜欢这样的,而且不方面mac下搜索和查找,所以想把它全部删掉,命令如下: find . -name "* *"| whi ...