D deyan666 Member Licensed User Longtime User Feb 7, 2015 #1 can anyone help me !!! Just need to find difference between two times but i think im over complicating it. i want the edittext field to be the input and i want the answer to be shown in an edit text. (for example edit text1 is 0700 and edit text2 is 1500 how can i calculate difference between these two)? for eg: DateTime.TimeFormat="HHmm" Dim a = DateTime.Time(EditText1.Text) Dim b = DateTime.Time(EditText3.Text) EditText3 = b - a why doesnt this work?
can anyone help me !!! Just need to find difference between two times but i think im over complicating it. i want the edittext field to be the input and i want the answer to be shown in an edit text. (for example edit text1 is 0700 and edit text2 is 1500 how can i calculate difference between these two)? for eg: DateTime.TimeFormat="HHmm" Dim a = DateTime.Time(EditText1.Text) Dim b = DateTime.Time(EditText3.Text) EditText3 = b - a why doesnt this work?
derez Expert Licensed User Longtime User Feb 7, 2015 #2 You need to use Dim a as long = DateTime.TimeParse(EditText1.Text) Dim b as long = DateTime.TimeParse(EditText3.Text) With this method you get ticks, so after calculating the difference b-a you need to convert it to time : EditText3 = DateTime.Time(b-a) Upvote 0
You need to use Dim a as long = DateTime.TimeParse(EditText1.Text) Dim b as long = DateTime.TimeParse(EditText3.Text) With this method you get ticks, so after calculating the difference b-a you need to convert it to time : EditText3 = DateTime.Time(b-a)
DonManfred Expert Licensed User Longtime User Feb 7, 2015 #3 Code: Dim a As Long = DateTime.TimeParse(edittext1.Text) Dim b As Long = DateTime.TimeParse(edittext2.Text) Dim p As Period = DateUtils.PeriodBetween(a,b) EditText3.Text = p.Hours&" hours, "&p.Minutes&" minutes" btw: Code: Dim b = DateTime.Time(EditText3.Text) is wrong... You need to use EditText2.Text here Upvote 0
Code: Dim a As Long = DateTime.TimeParse(edittext1.Text) Dim b As Long = DateTime.TimeParse(edittext2.Text) Dim p As Period = DateUtils.PeriodBetween(a,b) EditText3.Text = p.Hours&" hours, "&p.Minutes&" minutes" btw: Code: Dim b = DateTime.Time(EditText3.Text) is wrong... You need to use EditText2.Text here
derez Expert Licensed User Longtime User Feb 7, 2015 #4 Correction to my previous answer (I forgot about time offset) Code: Edittext3.text = DateTime.Time(b-a - DateTime.TimeZoneOffset * DateTime.TicksPerHour) You don't need dateutils for this. Upvote 0
Correction to my previous answer (I forgot about time offset) Code: Edittext3.text = DateTime.Time(b-a - DateTime.TimeZoneOffset * DateTime.TicksPerHour) You don't need dateutils for this.
Erel B4X founder Staff member Licensed User Longtime User Feb 8, 2015 #5 The only correct way to do it is with DateUtils as in @DonManfred code. Upvote 0
D deyan666 Member Licensed User Longtime User Feb 8, 2015 #6 Yeap. i Tried them both out and Don Manfred worked out well. One question. how can the answer come back as a float number. Example 0900- 1730 = 8.30 I need these floats to multiply with a standard rate of pay. Any Suggesitons? Upvote 0
Yeap. i Tried them both out and Don Manfred worked out well. One question. how can the answer come back as a float number. Example 0900- 1730 = 8.30 I need these floats to multiply with a standard rate of pay. Any Suggesitons?
Erel B4X founder Staff member Licensed User Longtime User Feb 8, 2015 #7 Code: Dim minutes As Int = p.Hours * 60 + p.Minutes Upvote 0
DonManfred Expert Licensed User Longtime User Feb 8, 2015 #8 Code: Dim worktime As Float = p.hours+(p.minutes/60) EditText3.Text = worktime Upvote 0