I have taken three text box and first text box from date, second text box to date, third text box total days. In the third text box to show how it will calculate total days automatically please Explain
Loading
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.
Satyapriya NayakPosted Jul 13, 2012, 4:11 AM
Thanks
Kunal VaishyaPosted Jul 12, 2012, 1:38 AM
try this one
use this function to calculate total days
int DaysBetween(DateTime d1, DateTime d2) {
first convert textbox values into dateTIme and pass into function it will return you total days
Satyapriya NayakPosted Jul 12, 2012, 1:34 AM
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Total_days_from_two_dates_csharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_total_Click(object sender, EventArgs e)
{
int Totaldays = duration(textBox1.Text, textBox2.Text);
label1.Text = Convert.ToString(Totaldays);
}
public int duration(string startdate, string enddate)
{
DateTime dt1 = DateTime.Parse(Convert.ToDateTime(textBox1.Text).ToString("dd/MM/yyyy"));
DateTime dt2 = DateTime.Parse(Convert.ToDateTime(textBox2.Text).ToString("dd/MM/yyyy"));
TimeSpan ts = dt2.Subtract(dt1);
int days = ts.Days;
return days;
}
}
}
Thanks
If this post helps you mark it as answer