Subtract PM time from AM time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I need to subtract a pm time from an am time, e.g. 10:00 a.m. from 1:00 p.m. to get 3

I have two textboxes for the time values and next to each is a dropdownlist to click indicating a.m. or p.m

Any help will be greatly appreciated

Sandy
 
Load up the times into DateTime objects - where each object would represent
the time of each textbox. Then you can do:

dateTime2.Subtract(dateTime1).Hours

This would give you the # of hours between the 2 datetime objects.

Sandy said:
Hello:

I need to subtract a pm time from an am time, e.g. 10:00 a.m. from 1:00 p.m. to get 3.

I have two textboxes for the time values and next to each is a
dropdownlist to click indicating a.m. or p.m.
 
Sandy,

Use the datediff function with a date interval of hour.

Dim lngDifference As Int64 = DateDiff(DateInterval.Hour,
Convert.ToDateTime(txtOne.text), Convert.ToDateTime(txtTwo.text))

HTH,

Raymond Lewallen

Sandy said:
Hello:

I need to subtract a pm time from an am time, e.g. 10:00 a.m. from 1:00 p.m. to get 3.

I have two textboxes for the time values and next to each is a
dropdownlist to click indicating a.m. or p.m.
 
Sandy,

This is probably a better way to do it. Although my example shoud work, I
really don't deal much with date types, so I would suggest ignoring my post
and using this example instead.

Raymond Lewallen
 
Back
Top