darknight
darknight

Reputation: 45

How can i add 1 day to a DateTime variable in Visual Basic?

What im trying to do is to add/sum a single day to an already declared DateTime variable. For context i take the DateTime value from a user input and then I want to add/sum 1 day for comparison and query purposes.

This is what i had in mind but i know this method wont work.

SQL.AddParam("@FromDate", FromDate + 1)

What would be the proper way to do this?

Upvotes: 0

Views: 1889

Answers (1)

Marco Tregnaghi
Marco Tregnaghi

Reputation: 75

Dim dateTime As DateTime
dateTime = dateTime.AddDays(1)

Datetime objects provide some functions to add time.

.AddDays(days as Double)
.AddHours(hours as Double)
.AddMinutes(minutes as Double)
.AddSeconds(seconds as Double)
.AddMilliseconds(milliseconds as Double)

Or you can try to pass directly to SQL your date + 1 day.

SQL.AddParam("@FromDate", DateAdd(DateInterval.DayOfYear, 1, FromDate))

Datetime.DateAdd function Microsoft's documentation: https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.dateandtime.dateadd?view=netcore-3.1

Upvotes: 1

Related Questions