Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to delete data from database in sql form date to ToDate
eg,
Suppose i have one month record from 1/9/2012 to 30/9/2012. and i want to delete Record From 12/9/2012 to 20/9/2012 .is it possible? if any have solution plz help me out this. thank you.
Posted
Updated 12-Oct-18 23:17pm

SQL
DELETE FROM MyTable WHERE DateField BETWEEN "12/09/2012" to "20/09/2012"

About between operator: http://msdn.microsoft.com/en-us/library/ms187922.aspx[^]
I assumed you are using SQLServer, but since this operator is an sql standard one, you will find it also in other engines. Btw, you can simply have the same with this one:
SQL
DELETE FROM MyTable WHERE DateField >= "12/09/2012" AND DateField <= "20/09/2012"
 
Share this answer
 
Comments
damodara naidu betha 11-Oct-12 2:05am    
Nice.5+
Zoltán Zörgő 11-Oct-12 3:12am    
Thank you.
If you want to delete records between two dates, you would just put that information in the WHERE clause like so:
SQL
DELETE
FROM myTable
WHERE myDate >= '12/9/2012' AND myDate <= '20/9/2012'

I would run that as a SELECT statement first to make sure you are getting the right records before actually running the delete. Basically, just replace the DELETE with SELECT * like so:
SQL
SELECT *
FROM myTable
WHERE myDate >= '12/9/2012' AND myDate <= '20/9/2012'
 
Share this answer
 
Comments
sahil012 10-Oct-12 8:08am    
thank you very much.
SQL
DELETE FROM tableName WHERE myDate BETWEEN @StartDate AND @endDate


http://msdn.microsoft.com/en-us/library/ms187922.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900