By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

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

P: 1
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
  2.  
  3.         Arrival_timeTextBox.Text = DateTime.Now.ToLongTimeString()
  4.     End Sub
  5.  
  6.     Private Sub DepartureTextBox_TextChanged(sender As Object, e As EventArgs) Handles DepartureTextBox.TextChanged
  7.  
  8. ??
  9.  
  10.     End Sub
  11. End Class
Feb 1 '15 #1
Share this Question
Share on Google+
2 Replies


IronRazer
P: 82
Hi,

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()
  4.  
  5.         Dim FiveMinutesAdded As Date = CurrentDate.AddMinutes(5)
  6.         DepartureTextBox.Text = FiveMinutesAdded.ToLongTimeString
  7.     End Sub
  8.  
Feb 1 '15 #2

Frinavale
Expert Mod 5K+
P: 9,731
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.

-Frinny
Feb 3 '15 #3

Post your reply

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