如何在sql server 2008中获得一周的最后一天和一周的最后一天? [英] How to get first day of the week and last day of the week in sql server 2008?

查看:217
本文介绍了如何在sql server 2008中获得一周的最后一天和一周的最后一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们输入一周中的任何一天,如何获得星期的第一天和最后一天?

How to get the first day of the week and last day of the week when we input any one day of a week?

例如,如果我们输入日期那么应该显示第一个(星期一)和最后一个(星期五)日。
,如果我们进入24-jan-2014,那么应该显示20-jan-2014和24-jan-2014。

For example if we enter a date then the first(Monday) and last (Friday) day should be displayed. that is if we enter 24-jan-2014 then 20-jan-2014 and 24-jan-2014 should be displayed.

关心

推荐答案

可以这样做:

DECLARE @yourdate date = getdate()
Select dateadd(ww, datediff(ww, 0, @yourdate), 0)
Select dateadd(ww, datediff(ww, 0, @yourdate), 4)

您将 @yourdate 设置为你想要的日期第一个SELECT将给你第一天,第二个SELECT将给你最后一个日期

You set @yourdate to the date you want. The first SELECT will give you the first day and the second SELECT will give you the last date

这篇关于如何在sql server 2008中获得一周的最后一天和一周的最后一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆