Skip to content

Compare Two Dates in Between SQL Query Using DateTimePicker

g s

Asked May 9, 2015, 5:16 AM EDT1 answer
Share
LinkedInX
 Compare Two Dates in Between SQL Query Using DateTimePicker  Calender Asp.Net C#

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Manoj Bhoir
    0
    Hi,

    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.
    0