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

 Posted by dhirenkaunar-15094 on 5/16/2012 | Category: Sql Server Interview questions | Views: 2044 | 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 

Comments or Responses

Login to post response