I have a question on Date difference in (My)Sql with c#.
In my database, I have a table containing date ranges like the following:
------------------------ From date to date ------------------------- 2012-07-01 2012-07-03 2012-07-05 2012-07-07 2012-07-10 2012-07-12 2012-07-13 2012-07-16 --------------------------
From those ranges, i want to calculate all included dates as result, i.e.:
2012-07-01 2012-07-02 2012-07-03 2012-07-05 2012-07-06 2012-07-07 2012-07-10 2012-07-11 2012-07-12 2012-07-13 2012-07-14 2012-07-15 2012-07-16
SELECT DATEDIFF('2012-01-01', '2012-02-02') does not work as I expect,
it gives only total number of days… i want all the dates between this, including the dates of the range (FromDate and ToDate).
Can you show me how I can implement this (in SQL or C#) ?
Thanks all I fixed it in C#.. cant find anything in mysql.
dtDetails is a datatable with values from DB (fromdate and to date)
Then i created one more datatable and stored all the values from (fromdate — todate)
then i will use that datatable.
if (dtDetails.Rows.Count > 0)
{foreach (DataRow dr in dtDetails.Rows)
{
DateTime startingDate = Convert.ToDateTime( dr["fromdate"]);
DateTime endingDate = Convert.ToDateTime(dr["todate"]);
DateTime newdate;
for (newdate = startingDate; newdate <= endingDate; newdate = newdate.AddDays(1))
{
DataRow dr2 = dt2.NewRow();
dt2.Rows.Add(newdate);
}
}
}