Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table tblSale with datetime field to store the date and time of every sale,,
user can check sales of any date, by selecting date from datetimepicker,

when i write query, date part can b same but time is different.
2nd thing is ho to write query that a user can select data according to particular month,,,
Posted

You can use the DATEPART function:
SQL
SELECT * FROM myTable WHERE DATEPART(year, @DATE)=DATEPART(year, dateField) AND DATEPART(month, @DATE)=DATEPART(month, dateField)
 
Share this answer
 
Comments
Uday P.Singh 8-Oct-11 12:58pm    
my 5!
You can use DATEDIFF[^] in your WHERE clause.

To compare on the same day use
SQL
SELECT * FROM tblSale WHERE DATEDIFF(day,salesDate,@SELECTEDDATE)=0

To compare on the same month use
SQL
SELECT * FROM tblSale WHERE DATEDIFF(month,salesDate,@SELECTEDDATE)=0

To compare on the same year use
SQL
SELECT * FROM tblSale WHERE DATEDIFF(year,salesDate,@SELECTEDDATE)=0
 
Share this answer
 
v4

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