What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 751 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > SQL Server Interview Questions > How to get First Day date and Last day D ...

How to get First Day date and Last day Date of the current week.

Interview question and answer by: Dhiren.Kaunar@Gmail.Com | Posted on: 5/16/2012 | Category: SQL Server Interview questions | Views: 918 | | Points: 40


Answer:

declare @start_date DATETIME

SET @start_date=dateadd(week, datediff(week, 0, getdate()), 0) ;
-- Get the last date of the last week
declare @end_date DATETIME
SET @end_date=dateadd(week, datediff(week, 0, getdate()), 6) ;

select
CONVERT(VARCHAR(10),@start_date,105) 'start day date of the week',
CONVERT(VARCHAR(10),@end_date,105) 'end day date of the week'

CONVERT(VARCHAR(10),@start_date,105) : This is used for removing the time part from the DateTime data type.

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Dhiren.Kaunar@Gmail.Com

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 12:33:32 AM