using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using uDate;

namespace DateDiff_timeDiff
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            string s = DateTime.Now.ToLongTimeString();
            
            label1.Text ="London : " + s;
            DateTime p =DateTime.Now.AddHours(3) ;
            s = p.ToLongTimeString();
            label2.Text = "KSA : " + s;
            label6.Text = uDate.dt.TimeDiff(DateTime.Now,p);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DateTime t1=dateTimePicker1.Value;
            DateTime t2=dateTimePicker2.Value;
           label3.Text= uDate.dt.DateDiff(t1, t2);
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

            
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

      
    }
}

the problem : When taking the difference between the days gives me the difference after 24 hours i wana it give me the want to do and I count the number of days just to enter in the first hour of the day the new... can anyone help to know where's the mistake here....:)

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

I tried in this function but it didn't any thing...
I have this func:

public static string   DateDiff( DateTime t2,DateTime t1)
        {
            TimeSpan  diffResult = t2.Subtract(t1);
            int i = diffResult.days;
            
       
            return i.ToString();

        }

but dont know what i have to do to get the days numb..

Have you tried diffResult.TotalDays? .Days only returns the day portion of the timespan, so if the difference between the dates was 1 month, 1 week and 1 day then .Days would return 1 whereas TotalDays would return 39 or something close to it depending on the dates you were comparing.

This article has been dead for over six months. Start a new discussion instead.