I have been working on a time clock program where the user can enter their time in and time out using two DateTimePickers, and it will tell them how many hours and minutes they worked. I was able to format the DateTimePicker to only show the hours and minutes. However, in my result it show's it with the hours, minutes, and seconds(hh:mm:ss) Ex. (08:00:47). I would like my result to only return the hours and minutes. Here is my code thus far:

Any help wouls be much appreciated, if you need any more info let me know.
Thank's soo much in Advanced!

        'Formats DateTimePicker for TimeIn to display only Hours and Minutes
        dtpTimeIn.CustomFormat = "hh:mm tt M/dd/y"
        dtpTimeIn.Format = DateTimePickerFormat.Custom
        dtpTimeIn.ShowUpDown = True

        'Formats DateTimePicker for TimeOut to display only Hours and Minutes
        dtpTimeOut.CustomFormat = "hh:mm tt M/dd/y"
        dtpTimeOut.Format = DateTimePickerFormat.Custom
        dtpTimeOut.ShowUpDown = True
    End Sub

    'Code for calculate button

        Dim dailyHrs As String
        dailyHrs = txtDailyHrs.Text

        'Displays answer as hh:mm:ss
        txtDailyHrs.Text = ((dtpTimeOut.Value - dtpTimeIn.Value).ToString())

You could put the result of subtracting the 2 values into a DateTime variable, then you can use the ToShortTimeString method to display the result. Or you could use the Format function, with something like this,"H:mm" for a format string.

Something like this:

    Dim ts As TimeSpan = dtpTimeOut.Value - dtpTimeIn.Value
    txtDailyHrs.Text = ts.Hours & ":" & ts.Minutes

Will display like this:

Date1: 08:00AM 1/24/13
Date2: 05:15PM 1/24/13

Text: 9:15

@Begginnerdev Oh my gosh thank you soo much!!! You don't know how much you helped me today. :D


No problem!

Please don't forget to close the thread by pressing the ("Mark This Thread as Solved") button at the bottom of the page!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.