Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
select * from table where createddate=@year

how to fetch the above sql query
Posted
Comments
itsathere 20-Jan-15 5:53am    
i have done it with below code

Int32 year = Convert.ToInt32(ddlyear.SelectedValue);
DateTime fromdate = Convert.ToDateTime(year + "-" + "01" + "-" + "01");
DateTime Todate = Convert.ToDateTime(year + "-" + "12" + "-" + "31");

Hi,
If you want to use only year then you can use

SQL
select * from table where createddate = YEAR (@YourDate)
 
Share this answer
 
v2
@year is a parameter.
So this should be replaced with the appropriate value before being executed in Sql Server.
 
Share this answer
 
Comments
itsathere 20-Jan-15 5:54am    
thanks for comment
C#
string Year = ddlYear.SelectedItem.Text;
DateTime Fdate = Convert.ToDateTime(Year + "-" + 01 + "-" + 01);
DateTime Tdate = Convert.ToDateTime(Year + "-" + 12 + "-" + 12);
 
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