.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Total days between two dates

Posted By:satyapriyanayak       Posted Date: October 31, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

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()





        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;





Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend