Creating


Dates

You can initialise a date in several ways:

Dim dtDateTime As System.DateTime 
dtDateTime = New System.DateTime(2004, 5, 12)

You can also include an exact hour, minute and second

Dim dtDateTime As System.DateTime 
dtDateTime = New System.DateTime(2004, 5, 12, 10, 20, 30)

If you want to initialise to just todays date (with no time) you can use the Today property

dtDateTime = System.DateTime.Today 

System.DateTime.Month - returns 1 for January
System.DateTime.Year - returns the current year (eg 2011)



Times




VB.Net - Date Data Type

The Date is an alias only available in VB.Net
For backwards compatibility you can still use the Date type as a synonym for the System.DateTime type.
The Now property returns the system date and time

Dim dtDate As Date 
dtDate = New Date().Now

The Today property returns the system date only

Dim dtDate As Date 
dtDate = New Date().Today

You can also initialise a date object by passing in the year, month and day values.

Dim dtDate As Date 
dtDate = New Date(2004, 5, 12)


Date variables are initialised to 1/1/0001 12:00:00am




© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext