Home > OS >  How do I use datetimepickers to find the difference between the entered start time and end time in h
How do I use datetimepickers to find the difference between the entered start time and end time in h

Time:06-05

I want to find the difference between the entered Start Time and End Time using date-time pickers in C# windows forms applications using c#. The output should be given in hours.

CodePudding user response:

Get two DateTimePickers and name them accordingly. Then go to property window and change their format to ”Time”. Below code is for the button which will trigger the calculation and show the output in a textbox.

    private void btnClickMe_Click(object sender, EventArgs e)
    {
        TimeSpan diff = dtpEndTime.Value - dtpStartTime.Value;
        int hours = diff.Hours   1;
        txtShowOutput.Text = Convert.ToString(hours);
    }
  • Related