Thursday, 17 May 2012

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


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


ans-

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.


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home