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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 11, 2012, 9:34 PM EDT
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
Kunal VaishyaRank #990 · 2K reputationPosted Jul 11, 2012, 9:38 PM EDT
try this one
use this function to calculate total days
int DaysBetween(DateTime d1, DateTime d2) {
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 13, 2012, 12:11 AM EDT
Thanks