1
Reply

Retrieve data using date range in .NET using C# with SQL SERVER

Prasad Vempati

Prasad Vempati

14y
11.5k
0
Reply

    I am using the following statement to retrieve the data between two dates passing to fromdate and todate programmatically. But I am getting data from different dates besides that date range.

    "SELECT SUM(CONVERT(DECIMAL(6,2),howmuchspent)) AS totalexpenses FROM MONTHLYEXPENSES WHERE expensesdate BETWEEN ' " + fromdate.Text + " ' AND '" + todate.Text + "' ";

    I did a test in SQL SERVER by passing dates directly as follows

    SELECT SUM(CONVERT(DECIMAL(6,2),howmuchspent)) AS totalexpenses FROM MONTHLYEXPENSES WHERE expensesdate BETWEEN ' 03/01/2010  ' AND '03/13/2010';

    This time I get exactly the data between those dates.

    I would like to know where I am doing wrong. Appreciate any help. Thank you.