How to compare dates in C# /sql server.

I have date at back end in 3/1/2012 12:00:00 AM
And from front end the date of entry is: 1-March-2012

string s = "select * from mstbt where feeddate>='" + Convert.ToDateTime(txtfdate.Text.Trim()) + "' and feeddate<='" + Convert.ToDateTime(txttdate.Text.Trim()) + "' order by 1 desc,2 desc,3 asc";
searchsanjaysharmaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
suvmitraConnect With a Mentor Commented:
select someColumn from someTable where DATEDIFF(seconds,GETDATE(),someDate) > ElapsedTimeColumn


msdn: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
0
 
Gustav BrockCIOCommented:
To play safe, you should convert to date, then format this to the correct string format for SQL Server:
string sqlfdate = "\'" + DateTime.Parse(txtfdate.Text.Trim()).ToString("yyyy-MM-dd") + "\'";
string sqltdate = "\'" + DateTime.Parse(txttdate.Text.Trim()).ToString("yyyy-MM-dd") + "\'";
s = "select * from mstbt where feeddate between " + sqlfdate + " and " + sqltdate + " order by 1 desc,2 desc,3 asc";

Open in new window

/gustav
0
 
searchsanjaysharmaAuthor Commented:
Thnx
0
 
Gustav BrockCIOCommented:
??
There was no ElapsedTimeColumn field but a start and an end date.

/gustav
0
All Courses

From novice to tech pro — start learning today.