Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I use datetimepickers to find the difference between the entered start time and end time in hours? Visual studio c#

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading