Date-Time
  • 13 Dec 2023
  • 1 Minute to read
  • Dark
    Light

Date-Time

  • Dark
    Light

Article summary

General

Values of type DateTime (alternativly named Date) can hold dates or date-times. A detailed explanation of the data-type can be found in the  Date Data-Type article of the Visual Basic .NET language documentation.

Constants

Constant date-time values are written using the following syntax:

Mail & Deploy Expression

#8/13/2002 12:14 PM#

You can also only specify a date:

Mail & Deploy Expression

#8/13/2002#

To access the current date-time, you can use the following expression:

Mail & Deploy Expression

DateTime.Now

To access the current date, you can use the following expression:

Mail & Deploy Expression

Date.Today

To access the current date-time, you can use the following expression:

Mail & Deploy Expression

DateTime.Now

Calculations

AddDays

The AddDays function returns a date that has the provided number of days added or subtracted; the following expression returns the date for yesterday:

Mail & Deploy Expression

Date.Today.AddDays(-1)

AddMonths

The AddMonths function returns a date that has the provided number of months added or subtracted; the following expression returns today minus 1 month:

Mail & Deploy Expression

Date.Today.AddMonths(-1)


Was this article helpful?

What's Next