Home > Database > Mysql Tutorial > 取得上周一和上周日sql语句

取得上周一和上周日sql语句

WBOY
Release: 2016-06-07 17:49:28
Original
2528 people have browsed it

本文章来介绍几个取得上周一和上周日sql语句有需要了解的朋友可进入学习。

获取上一周


-- 上周一的

 代码如下 复制代码

title from info where DATEDIFF(DD,DATEADD(DW,-6-DATEPART(DW,getdate()),getdate()),title_date)=0;


获取上周一

把titleddtime改成你的字段名字啊

 代码如下 复制代码

select * from info 
where  DATEDIFF(dd,DATEADD(day,-7,DATEADD(week, DATEDIFF(week, '', getdate()), '')),titleddtime) =0
or
  DATEDIFF(dd,DATEADD(day,-5,DATEADD(week, DATEDIFF(week, '', getdate()), '')),titleddtime) =0
or
  DATEDIFF(dd,DATEADD(day,-3,DATEADD(week, DATEDIFF(week, '', getdate()), '')),titleddtime) =0

上周一与上周日sql语句

 代码如下 复制代码

SET DATEFIRST 1
DECLARE @day1 DATETIME
DECLARE @day7temp DATETIME
DECLARE @day7 VARCHAR(100)
SET @day1 = convert(char(10),dateadd(dd, - DATEPART (weekday , getdate())-6,getdate()),120)
SET @day7temp = convert(char(10),dateadd(dd, - DATEPART (weekday , getdate()),getdate()),120)
SET @day7 = CAST(YEAR(@day7temp) AS VARCHAR(4)) + '-' + CAST(MONTH(@day7temp) AS VARCHAR(2)) + '-' + CAST(DAY(@day7temp) AS VARCHAR(2)) + ' 23:59:59'
select  @day1
select @day7

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template