Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create start date and end date with SQL?

string st = '01/2012' (MM/yyyy)

I want to get the data between 01/01/2012 and 31/01/2012

How to create a start date and end date according to month and year format?

For Example

st = 02/2012

Select * from table where dates between 01/02/2012 and 29/02/2012

How to make a query for adding start and end date of the month?

like image 474
Gopal Avatar asked Jan 10 '12 04:01

Gopal


1 Answers

The following should give you the last day of the current month on sql-server-2000:

SELECT DATEADD(second,-1,DATEADD(month, DATEDIFF(month,0,GETDATE())+1,0))

To find the last day of the month for a given month try:

DECLARE @thisDate DATETIME
SET @thisDate = '06/27/2011'
SELECT DATEADD(second,-1,DATEADD(month, DATEDIFF(month,0,@thisDate)+1,0))
like image 146
Ilion Avatar answered Oct 06 '22 01:10

Ilion