Browse this blog

Wednesday, September 2, 2009

Calculation with date and time in VisualBasic 2008

At the moment I'm writing an application who deals with calculation with date and time. I had to search for a long time to find the right informations I needed for this application. So I thought it can't be wrong to write a post about the informations I found.

At first you have to implement the variable "datum":

Dim datum As New DateTime

Now you need the actual time:

datum = My.Computer.Clock.LocalTime

After this you have to name how much time you want to add or subtract. You can do that with either with a positive prefix or a negative:

datum = datum.AddHours(4)

Now you could write that in a label:

Label1.Text() = datum

Also you have many more possibilities to add or subtract time:

.AddYears

.AddMonths

.AddDays

.AddSeconds

.AddHours

.AddTicks

.AddMilliseconds

.AddMinutes

Now the whole coding example for the comprehension:

Dim datum As New DateTime

datum = My.Computer.Clock.LocalTime

datum = datum.AddHours(4)

Label10.Text() = datum

No comments:

Post a Comment