计算给定日期所在星期的第2天(星期日为第一天)sql语句
Jun 07, 2016 pm 05:47 PM计算给定日期所在星期的第2天(星期日为第一天)
declare @date datetime
set @date= getdate()
--思路:当前日期+星期一(每周的第2天)与当前日期的差的天数
--datepart(weekday,date)的返回值与@@datefirst相关
set datefirst 7 -- 或者设置为美国英语set language us_english; (星期日为第一天)
select dateadd(day,2-datepart(weekday,@date),@date) as '所在星期的第二天,星期一'
--星期一,与sql server语言版本或@@datefirst无关
--'1900-01-01' 是星期一,'1900-01-01' 再加上(当前日期与1900-01-01差的星期数)个星期
select dateadd(week,datediff(week,0,@date),0) as '所在星期的星期一'
go

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo

How to calculate addition, subtraction, multiplication and division in word document

CUDA's universal matrix multiplication: from entry to proficiency!

How to count the number of elements in a list using Python's count() function

How to remove the date that appears automatically when printing from PPT handouts

How to use the Math.Pow function in C# to calculate the power of a specified number

Count the number of occurrences of a substring recursively in Java

How to display date and seconds in the top bar of Ubuntu 17.10?
