In this blog we will know how to calculate total days
between two dates.
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;
}
}
}