Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Integer to TimeSpan

Status
Not open for further replies.

Linda224

Programmer
Joined
Dec 6, 2006
Messages
80
Location
US
Hello
Does any one no how to convert an integer to a timespan

Thank you
 
What exactly are you trying to do?
 
I am adding up the number of hours that the user selects in a work week schedule. That works fine but I need it to subract an hour or half hour lunch per day depending on what they choose. So if they choose 2 1/2 hours of lunch time I need to subtract 2.5 hours from the total. I have a list box for the number of hours they can choose for lunch and the values are integers so I need to convert the integer to a timespan to subtract from the total hours. Or I'm sure there is another simpler way to do this.

Thank you for any help
 
This might help. The example subtracts 2.5 hours from a time span of 8 hours and 30 minutes:
Code:
Dim workedHours As TimeSpan = New TimeSpan(8, 30, 0)

Dim hrs As Double = 2.5

Console.WriteLine(workedHours.Subtract(TimeSpan.FromHours(hrs)))
 
You can always take the end time datetime variable and do

dteEnd.AddMinutes(-30).AddHours(-2) (or whatever lunch they take) and then do a time span and get the hours worked.
 
Thanks for your help you guys are awesome!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top