i have
No of months
Start date
end date in my page
when i give number of months 3 and start date 10/7/2015 then end date will calculated to 10/9/2015 automatically.
And now i want to create extra columns in database i.e June-2015, july and august
in this table or another table
in this table or another table
how to create month columns automatically based on Number months and start date,end date
my code is
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)
{
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());
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted Jul 10, 2015, 5:18 AM