Hi there,
I hope your all alright. Im trying to get the difference between date values in two textboxs, textbox1.text and textbox2.text and the difference being the number of days in between the two date values to be viewed in textbox3.text.
Below is the code I attempted to use but I am getting errors
{
decimal a = System.Convert.ToDateTime(textBox16.Text);
decimal b = System.Convert.ToDateTime(textBox17.Text);
decimal c = (b - a);
textBox18.Text = c.ToString();
}
Any help will be greatly appreciated.
Thanks and Best Regards to Everyone.

Satyapriya NayakPosted Jul 13, 2012, 8:32 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
Santhosh Kumar JayaramanPosted Jul 13, 2012, 8:54 AM
{
DateTime a = System.Convert.ToDateTime(textBox16.Text);
DateTime b = System.Convert.ToDateTime(textBox17.Text);
double c = (b - a).Days;
textBox18.Text = c.ToString();
}