Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
in sqlserver,i created the table with orderdate as datetime.now i want to
separate the date only and also i want to compare with system date. during
comparison, if it exceeds 12 months ,service charges to be paid.

C#
protected void Button1_Click(object sender, EventArgs e)
   {

       int result;
       cmd = new SqlCommand(" SELECT DATEDIFF(mm,"+DropDownList1.SelectedValue.ToString()+","+System.DateTime.Now.ToString()+") from productorder where email='"+Session["username"]+"'",con);
       result = cmd.ExecuteNonQuery();

   }
Posted
Updated 16-Feb-11 1:38am
v2
Comments
Sunasara Imdadhusen 16-Feb-11 7:38am    
Added code formatting!
Sunasara Imdadhusen 16-Feb-11 7:39am    
Now, what is your problem?

If you want to select data which is more than 12 months then you can do the following:
SQL
select * from table_name where datediff(month, your_table_date_field, getDate()) > 12

 
Share this answer
 
v2
You now select the difference in months between the date in the DropDownList and now if the user email exists in product order. So, it could work but the remember that the dates (as far as shown here) are not from the database.

It would probably be more safe to check it directly with the date in the database instead of the date given in the DropDownList1. Also, I wouldn't encourage inline sql and recommend using a stored procedure.

Good luck!
 
Share this answer
 
in database it would have stored like this

2/17/2011 2:11:51

you can see that there is a space between time stamp and date stamp

you can use split function to convert it to array like this Unknown size Numeric Arrays from Strings - dontumindit[^]

or for builtin function see this

DATEDIFF (Transact-SQL)[^]
 
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