Sql日期查询-SQL查询今天、昨天、7天内、30天
今天的所有数据: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天的更多相关文章
- Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等)
Linq to SQL 语法查询(链接查询,子查询 & in操作 & join,分组统计等) 子查询 描述:查询订单数超过5的顾客信息 查询句法: var 子查询 = from c i ...
- SQL Server T-SQL高级查询
name like 'ja%'; select * from student where name not like '%[j,n]%'; select * from student where na ...
- 【转】SQL Server T-SQL高级查询
SQL Server T-SQL高级查询 高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; //查询student ...
- SQL Server T-SQL高级查询(转)
高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex fr ...
- util-C# 复杂条件查询(sql 复杂条件查询)查询解决方案
ylbtech-funcation-util: C# 复杂条件查询(sql 复杂条件查询)查询解决方案 C# 复杂条件查询(sql 复杂条件查询)查询解决方案 1.A,Ylbtech.Model返回 ...
- oracle 基础SQL语句 多表查询 子查询 分页查询 合并查询 分组查询 group by having order by
select语句学习 . 创建表 create table user(user varchar2(20), id int); . 查看执行某条命令花费的时间 set timing on: . 查看表的 ...
- SQL Server T-SQL高级查询【转】
高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from ...
- SQL Server T-SQL高级查询1
高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from ...
- sql like 通配符 模糊查询技巧及特殊字符
最近碰到like模糊匹配的问题,找到一些答案接触迷惑,觉得有知识是自己忽略的,现在整理出来,既强化记忆,又是一次记录,以下转自一篇Blog,关于sql server like的通配符和字符带通配符的处 ...
- SQL Server 基础 03 查询数据基础
查询数据 简单的查询 create table stu_info ( sno int not null ,sname ) not null ,sex ) not null ,birth ) not n ...
随机推荐
- pip崩了, 解决 ModuleNotFoundError: No module named 'pip'.
今天 在windows下用pip 安装数据库模块pymysql 把pip 弄崩了,直接出现下面的错误.都是红字, 再输入pip install pymysql ,会报错ModuleNotFound ...
- javascript预览本地图片
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Linux进阶之Shell编程
1.什么是Shell Shell是一个命名行解释器,它为用户提供一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动.挂起.停止甚至是编写一些程序. 2.Shell脚本 ...
- HAProxy+Keepalived高可用负载均衡
一 基础准备 1.1 部署环境及说明 系统OS:CentOS 6.8 64位 HAProxy软件:HA-Proxy version 1.5.18 Keepalived软件:keepalived-1.3 ...
- 从0开始部署GPU集群-1:k8s部署生态
1 k8s:nvidia deepops 2 批处理:华为volcano 3 工作流:argo
- 记录linux上mongo迁移使用的命令
首先mongodb的文件路径必须在系统盘,这里是 这里安装路径 /usr/mongodb/bin 一般迁移的只是db文件夹和log文件 看配置文件内容 port=27017 #端口 dbpath=/d ...
- vooya --- a YUV player and a generic raw data player
vooya是一个raw数据播放器,可播放yuv数据,兼容win.linex以及mac平台. 下载地址:https://www.offminor.de/(见最下面) ubuntu需要安装依赖: apt ...
- Real-time Multiple People Tracking with Deeply Learned Candidate Selection and Person Re-identification
Real-time Multiple People Tracking with Deeply Learned Candidate Selection and Person Re-identificat ...
- linux 运行时限制CPU核数、内存、读写速度
systemd-run --scope -p MemoryLimit=4G \ -p "BlockIOReadBandwidth=/dev/sdb1 150M" \ -p &quo ...
- golang testing 无法获取覆盖率问题
https://segmentfault.com/q/1010000021142202