Compare Two Dates in Between SQL Query Using DateTimePicker Calender Asp.Net C#
Compare Two Dates in Between SQL Query Using DateTimePicker
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Manoj BhoirRank #599 · 4K pointsPosted May 9, 2015, 6:57 AM EDT
Your question is not clear. If you simply want to compare two date then you can do this in C# code there is no need of SQL Query.
Use DateTime.Compare(Date1, Date2)
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
Fore more details check this link :
https://msdn.microsoft.com/en-us/library/system.datetime.compare%28v=vs.110%29.aspx
If you want to Select Data from table with specific date range you can use BETWEEN.
Check this sample query :
Select * From TableName Where DateColumnName BETWEEN 'YYYY-MM-DD' AND 'YYYY-MM-DD'
Here instead of YYYY-MM-DD pass your Datepicker values in specified format.
I hope this will help you.