Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to show last three month data in datalist;
i hv one column in table date which is datetime type.
if user want to see last three month data then they can,so how to calculate data
Posted
Comments
P.Salini 12-Oct-11 8:36am    
clarify your question
sandesh.mumbai 12-Oct-11 8:40am    
please clarify what exactly u r doing

Something like

C#
List<datetime> dates = new List<datetime>();

DateTime userDate = DateTime.Now;

DateTime currentDate = userDate.AddMonths(-3);

while (currentDate <= userDate)
{
    dates.Add(currentDate);
    currentDate = currentDate.AddDays(1);
}

DataList dl = new DataList();
dl.DataSource = dates;
dl.DataBind();
</datetime></datetime>
 
Share this answer
 
v3
You need to create a date range for your query. What the query itself looks like is entirely dependent on what your data source is going to be. (i.e. sql, excel file, text file???). If your user picks a date and you want to calculate the date 3 months previous, then you just need to do the following:
C#
DateTime startDate = userDate.AddMonths( -3 );
 
Share this answer
 
SQL
SELECT * FROM table WHERE DATEDIFF(mm,date column,getdate())<=3
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900