Home Database Mysql Tutorial 计算给定日期所在星期的第2天(星期日为第一天)sql语句

计算给定日期所在星期的第2天(星期日为第一天)sql语句

Jun 07, 2016 pm 05:47 PM
date Week given calculate

计算给定日期所在星期的第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
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo Mar 30, 2024 pm 07:26 PM

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 How to calculate addition, subtraction, multiplication and division in word document Mar 19, 2024 pm 08:13 PM

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

CUDA's universal matrix multiplication: from entry to proficiency! CUDA's universal matrix multiplication: from entry to proficiency! Mar 25, 2024 pm 12:30 PM

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 count the number of elements in a list using Python's count() function Nov 18, 2023 pm 02:53 PM

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 remove the date that appears automatically when printing from PPT handouts Mar 26, 2024 pm 08:16 PM

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 How to use the Math.Pow function in C# to calculate the power of a specified number Nov 18, 2023 am 11:32 AM

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 Count the number of occurrences of a substring recursively in Java Sep 17, 2023 pm 07:49 PM

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? How to display date and seconds in the top bar of Ubuntu 17.10? Jan 08, 2024 am 10:41 AM

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

See all articles