tufanv Expert Licensed User Longtime User Apr 30, 2018 #1 Hello, I am absolutely doing something wrong. I want to take the minute and second difference between the click of 2 buttons. for the first button : Code: Copy dim time1 as long =DateTime.Time(DateTime.Now) for the second button : Code: Copy dim time2 as long =DateTime.Time(DateTime.Now) time1 and time 2 are correct , it displays with this format : 17:09:39 , but this gives 0 : Log(DateUtils.PeriodBetween(time1,time2)) The time now is: 17:21:29 The time now is: 17:21:34 [IsInitialized=1, Years=0, Months=0 , Days=0, Hours=0, Minutes=0 , Seconds=0] as it must give 0 minutes and 5 seconds. I am doing a very simple mistake somewhere but datetuils topic is not so detailed so i cant get it. Can you help out ? thanks
Hello, I am absolutely doing something wrong. I want to take the minute and second difference between the click of 2 buttons. for the first button : Code: Copy dim time1 as long =DateTime.Time(DateTime.Now) for the second button : Code: Copy dim time2 as long =DateTime.Time(DateTime.Now) time1 and time 2 are correct , it displays with this format : 17:09:39 , but this gives 0 : Log(DateUtils.PeriodBetween(time1,time2)) The time now is: 17:21:29 The time now is: 17:21:34 [IsInitialized=1, Years=0, Months=0 , Days=0, Hours=0, Minutes=0 , Seconds=0] as it must give 0 minutes and 5 seconds. I am doing a very simple mistake somewhere but datetuils topic is not so detailed so i cant get it. Can you help out ? thanks
M Mahares Expert Licensed User Longtime User Apr 30, 2018 #2 tufanv said: I am absolutely doing something wrong. Click to expand... You need something like this: Code: Copy Dim time1 As Long =DateTime.Now Dim time2 As Long =DateTime.now + 1230000 'put the second button click time here Dim p As Period p=DateUtils.PeriodBetweenInDays(time1,time2) Log($"$2.0{p.Minutes} mn $2.0{p.Seconds} sec "$) 'displays 20 mn 30 sec Upvote 0
tufanv said: I am absolutely doing something wrong. Click to expand... You need something like this: Code: Copy Dim time1 As Long =DateTime.Now Dim time2 As Long =DateTime.now + 1230000 'put the second button click time here Dim p As Period p=DateUtils.PeriodBetweenInDays(time1,time2) Log($"$2.0{p.Minutes} mn $2.0{p.Seconds} sec "$) 'displays 20 mn 30 sec
tufanv Expert Licensed User Longtime User May 1, 2018 #3 Mahares said: You need something like this: Code: Copy Dim time1 As Long =DateTime.Now Dim time2 As Long =DateTime.now + 1230000 'put the second button click time here Dim p As Period p=DateUtils.PeriodBetweenInDays(time1,time2) Log($"$2.0{p.Minutes} mn $2.0{p.Seconds} sec "$) 'displays 20 mn 30 sec Click to expand... tried this: Code: Copy Sub lblstart_Click If lblstart.Text.Contains("Start") Then Dim time1 As Long =DateTime.Now lblstart.Text="Stop Recording" lblstart.Color=Colors.Red Else Dim time2 As Long =DateTime.now Dim pl As Period pl=DateUtils.PeriodBetweenInDays(time1,time2) Log($"$2.0{pl.Minutes} mn $2.0{pl.Seconds} sec "$) 'displays 20 mn 30 sec lblstart.Text="Start Recording" lblstart.Color=Colors.Rgb(58,197,0) End If End Sub when the button is clicked for the first time it is time1 and when it is clicked second time it is time2 . I press the button second time after 3-4 seconds later but what i got is : 45 mn 43 sec Upvote 0
Mahares said: You need something like this: Code: Copy Dim time1 As Long =DateTime.Now Dim time2 As Long =DateTime.now + 1230000 'put the second button click time here Dim p As Period p=DateUtils.PeriodBetweenInDays(time1,time2) Log($"$2.0{p.Minutes} mn $2.0{p.Seconds} sec "$) 'displays 20 mn 30 sec Click to expand... tried this: Code: Copy Sub lblstart_Click If lblstart.Text.Contains("Start") Then Dim time1 As Long =DateTime.Now lblstart.Text="Stop Recording" lblstart.Color=Colors.Red Else Dim time2 As Long =DateTime.now Dim pl As Period pl=DateUtils.PeriodBetweenInDays(time1,time2) Log($"$2.0{pl.Minutes} mn $2.0{pl.Seconds} sec "$) 'displays 20 mn 30 sec lblstart.Text="Start Recording" lblstart.Color=Colors.Rgb(58,197,0) End If End Sub when the button is clicked for the first time it is time1 and when it is clicked second time it is time2 . I press the button second time after 3-4 seconds later but what i got is : 45 mn 43 sec
M Mahares Expert Licensed User Longtime User May 1, 2018 #4 Dim time1 As Long =DateTime.Now needs to be outside the If loop. Code: Copy Sub lblstart_Click Dim time1 As Long =DateTime.Now Upvote 0
Dim time1 As Long =DateTime.Now needs to be outside the If loop. Code: Copy Sub lblstart_Click Dim time1 As Long =DateTime.Now
DonManfred Expert Licensed User Longtime User May 1, 2018 #5 Code: Copy Sub btnStart_Click starttime = DateTime.Now End Sub Sub btnStop_Click stoptime = DateTime.Now Dim pl As Period pl=DateUtils.PeriodBetweenInDays(starttime,stoptime) lblResult.Text = pl Log(pl) End Sub Code: Copy [Days=0, Hours=0, IsInitialized=true , Minutes=0, Months=0, Seconds=7 , Years=0] Attachments timecalc.zip timecalc.zip 9.1 KB · Views: 430 Upvote 0
Code: Copy Sub btnStart_Click starttime = DateTime.Now End Sub Sub btnStop_Click stoptime = DateTime.Now Dim pl As Period pl=DateUtils.PeriodBetweenInDays(starttime,stoptime) lblResult.Text = pl Log(pl) End Sub Code: Copy [Days=0, Hours=0, IsInitialized=true , Minutes=0, Months=0, Seconds=7 , Years=0]
tufanv Expert Licensed User Longtime User May 1, 2018 #6 DonManfred said: Code: Copy Sub btnStart_Click starttime = DateTime.Now End Sub Sub btnStop_Click stoptime = DateTime.Now Dim pl As Period pl=DateUtils.PeriodBetweenInDays(starttime,stoptime) lblResult.Text = pl Log(pl) End Sub Code: Copy [Days=0, Hours=0, IsInitialized=true , Minutes=0, Months=0, Seconds=7 , Years=0] Click to expand... Mahares said: Dim time1 As Long =DateTime.Now needs to be outside the If loop. Code: Copy Sub lblstart_Click Dim time1 As Long =DateTime.Now Click to expand... Thanks for the help guys. I didn't know that if it was in the if loop , will not work properly. Regards Upvote 0
DonManfred said: Code: Copy Sub btnStart_Click starttime = DateTime.Now End Sub Sub btnStop_Click stoptime = DateTime.Now Dim pl As Period pl=DateUtils.PeriodBetweenInDays(starttime,stoptime) lblResult.Text = pl Log(pl) End Sub Code: Copy [Days=0, Hours=0, IsInitialized=true , Minutes=0, Months=0, Seconds=7 , Years=0] Click to expand... Mahares said: Dim time1 As Long =DateTime.Now needs to be outside the If loop. Code: Copy Sub lblstart_Click Dim time1 As Long =DateTime.Now Click to expand... Thanks for the help guys. I didn't know that if it was in the if loop , will not work properly. Regards