Click here to Skip to main content
15,885,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
i have 3 controls

No of months 5
Start date 1/6/2015
End Date 1/10/2015

am binding end date automatically by using number of months and start date
then am inserting these values into table 1

i want to bind these details from database as

NoofMonths Startdate EndDate 1-june-2015 1-July-2015 1-Aug-2015 1-sep-2015 1-oct-2015

i want to bind number of months 5 as individual months

please suggest me possible ways to get it

i have posted this question already but still i cant get it.


my code
Demo.cs

protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("Insert into monthcal (NoOfMonths,StartDate,EndDate) values (@NoOfMonths,@StartDate,@EndDate)", con);
cmd.Parameters.AddWithValue("@NoOfMonths", txtNoOfMonths.Text.ToString());
cmd.Parameters.AddWithValue("@StartDate", txtStartDate.Text.ToString());
cmd.Parameters.AddWithValue("@EndDate", txtEndDate.Text.ToString());
con.Open();
cmd.ExecuteNonQuery();

}
protected void txtStartDate_TextChanged(object sender, EventArgs e)
{

//DateTime startDate = DateTime.Parse(txtStartDate.Text);
//startDate.AddMonths(Convert.ToInt32(txtNoOfMonths.Text));
//txtEndDate.Text = startDate.ToString("yyyy/MM/dd");


string inputString = txtStartDate.Text;
DateTime dt = DateTime.ParseExact(inputString, "yyyy/MM/dd", CultureInfo.InvariantCulture);
dt = dt.AddMonths(Convert.ToInt32(txtNoOfMonths.Text));
txtEndDate.Text = dt.ToString("yyyy/MM/dd");


DateTime Date1 = Convert.ToDateTime(txtStartDate.Text);
DateTime Date2 = Convert.ToDateTime(txtEndDate.Text);
//int Datediff = ((Date2.Year - Date1.Year) * 12) + Date1.Month - Date2.Month;
int DayDiff = (Date2.Date - Date1.Date).Days;
Label1.Text = "Total days" + " " + (DayDiff.ToString());




please help

Thanks in advance
Posted

1 solution

As far as I understand, you want to calculate dates in SQL. As you have tagged SQL Server, then for that, you need to use SQL Server DATEADD() Function[^].
 
Share this answer
 

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