Data types

Modified on Wed, 17 May, 2023 at 12:49 PM

Depending on the data-type of the constant value (see Constant Values) or dynamic value (see Dynamic Values), you can access certain properties of the value and/or manipulate it.


Date-Time 

More information about all available functions and properties of date-times can be found in the documentation of Microsoft .NET Framework (.NET Framework Documentation on Dates). Generally speaking, the date data type can be accessed using the Date class literal; this class exposes a number of properties and functions.

Current Local Date-Time 

If you want to access the current, local date-time, you can do this by using the following syntax:

Date.Now

Current UTC Date-Time 

If you want to access the current, UTC date-time, you can do this by using the following syntax:

Date.UtcNow

Year, Month, Day, Hour and Minute 

If you just want to use a specific property (e.g. such as the number of the month) of a date, you can use this using one of the following syntaxes:

<Date_Value>.Year
<Date_Value>.Month
<Date_Value>.Day
<Date_Value>.Hour
<Date_Value>.Minute

For example, if you want to access the current year (according to the local date-time), you can use the following syntax:

Date.Now.Year

Calculations 

Visual Basic .NET also offers functionality to perform calculations on dates. 

Adding or Subtracting Days

If you want to add 5 days to the current, local date-time, you can use the following syntax:

Date.Now.AddDays(5)

You can also supply negative values in order to subtract days. 

Adding or Subtracting Months 

If you want to add 5 months to the current, local date-time, you can use the following syntax:

Date.Now.AddMonths(5)

You can also supply negative values in order to subtract months.

Creating a new Date 

You can create a new date (without time) by supplying the individual numeric components for a year, month, and day using the following syntax:

New Date(2018,12,31)

The values supplied do not need to be constant values. You could, for instance, get the date which equals the first day of the next month, by using the following syntax:

New Date(Date.Now.AddMonths(1).Year,Date.Now.AddMonths(1).Month,1)

Creating a new Date-Time 

You can create a new date (including time) by supplying the individual numeric components for a year, month, day, hour, minute and second using the following syntax:

New Date(2018,12,31,18,30,15)

The above expression equals the 31st of December 2018, 6:30 PM and 15 seconds.


Formatting and Conversions 

You can convert a date-time into a text representation by using the ToString function. This conversion process uses the culture settings of the user under which the expression is being executed or another culture provided by the context, e.g. culture-aware reports (see Culture Awareness). If you use the following syntax, the date-time value will be converted to a textual representation using the default format of the applicable culture:

<Date_Value>.ToString()

For instance, if you want to convert the current, local date-time into a textual representation using the default format of the applicable culture, you can use the following syntax:

Date.Now.ToString()

However, the ToString function also allows you to supply a standard format string (Standard Date Time Format Strings Documentation) or a more flexible custom format string (Custom Date Time Format Strings Documentation). For instance, if you want to convert the current, local date-time into a textual representation that contains the 2-digit day, then a dot, then the 2-digit month, then a dot, and then the 4-digit year by using a custom format string, you can use the following syntax:

Date.Now.ToString("dd.MM.yyyy")

If you want to include time-information in the textual representation (a 2-digit hour in 24-hour format, then ":", then a 2-digit minute), then you can use the following syntax:

Date.Now.ToString("dd.MM.yyyy HH:mm")

If you want to convert the current, local date into a textual representation according to the short date pattern of the current culture, you can use the following syntax:

Date.Now.ToString("d")


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article