Getting StartDate and EndDate using SQL query
-
Hi, I have a requirement to select the starting date and ending date of a month if I give a particular date as a parameter. HOw to do that? For eg> If I give the select statement as below: select startdate, enddate from where particulardate = '17/03/2008'. If I execute this query, I should get the start date as '01/03/2008' and end date as '31/03/2008' HOw to achieve this in SQL Server? Pls help Regards meeram.
Meeram395
-
Hi, I have a requirement to select the starting date and ending date of a month if I give a particular date as a parameter. HOw to do that? For eg> If I give the select statement as below: select startdate, enddate from where particulardate = '17/03/2008'. If I execute this query, I should get the start date as '01/03/2008' and end date as '31/03/2008' HOw to achieve this in SQL Server? Pls help Regards meeram.
Meeram395
Getting End Date 1. Add 1month to the given date taking 1st day and year of given date 2. which returns 1st of next month from given date 3. subtract 1day which returns last day of given month
DECLARE @GivenDate AS DateTime SET @GivenDate = GetDate() SELECT DateAdd(DD, -1, DateAdd(MM, 1, Cast(Month(@GivenDate) AS VarChar(2)) + '/01/' + Cast(Year(@GivenDate) AS VarChar(4))))
Getting Start date similar to the end date take day as 1 with month & year from given dateRegards KP
-
Getting End Date 1. Add 1month to the given date taking 1st day and year of given date 2. which returns 1st of next month from given date 3. subtract 1day which returns last day of given month
DECLARE @GivenDate AS DateTime SET @GivenDate = GetDate() SELECT DateAdd(DD, -1, DateAdd(MM, 1, Cast(Month(@GivenDate) AS VarChar(2)) + '/01/' + Cast(Year(@GivenDate) AS VarChar(4))))
Getting Start date similar to the end date take day as 1 with month & year from given dateRegards KP