470,850 Members | 1,393 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,850 developers. It's quick & easy.

"Add 5 minutes to current time which is in string"

Hi, I have taken two textboxes, 1 shows the current time i.e system time, while in other textbox, I want to show five minutes added to the system time. How to do that?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Arrival_timeTextBox_TextChanged(sender As Object, e As EventArgs) Handles Arrival_timeTextBox.TextChanged
  3.         Arrival_timeTextBox.Text = DateTime.Now.ToLongTimeString()
  4.     End Sub
  6.     Private Sub DepartureTextBox_TextChanged(sender As Object, e As EventArgs) Handles DepartureTextBox.TextChanged
  8. ??
  10.     End Sub
  11. End Class
Feb 1 '15 #1
2 4663
83 64KB

You most likely are not going to want to set the textbox`s text inside the same textbox`s TextChanged event. Depending on what you are doing it may cause an infinite loop.

You will want to use a Date variable to assign the current date to and display that in one textbox. Then you can use the Date.AddMinutes method to add 5 minutes to that date. Then display that in the other textbox.

Here is an example:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim CurrentDate As Date = Now
  3.         Arrival_timeTextBox.Text = CurrentDate.ToLongTimeString()
  5.         Dim FiveMinutesAdded As Date = CurrentDate.AddMinutes(5)
  6.         DepartureTextBox.Text = FiveMinutesAdded.ToLongTimeString
  7.     End Sub
Feb 1 '15 #2
9,735 Expert Mod 8TB
Use one of the DateTime.TryParse methods to retrieve the date out of the text box and convert it into a DateTime type.

Once you have converted/parsed the string into a DateTime type you can use the methods like the AddMinutes Method to do what you want.

Feb 3 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Chris | last post: by
18 posts views Thread by Tim Quon | last post: by
4 posts views Thread by Gary Wessle | last post: by
4 posts views Thread by iwdu15 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.