O'Reilly logo

Special Edition Using Microsoft® Visual Basic® .NET by Jeff Spotts, Brian Siler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Date and Time Values

Visual Basic .NET provides the versatile Date data type to store date and time values. The following lines of code are examples of using date variables:

Dim dtWWII As Date = #12/7/1941# 
Dim dtKing As Date = Convert.ToDateTime("Aug 16, 1977 4:00 PM") 
Dim dtJFK As Date = Convert.ToDateTime("November 23, 1963") 
Dim dtMoon As New Date(1969, 7, 20) 

The first line of the previous code uses the pound (#) symbol to assign a date value directly to a variable of type date. The next two examples use methods to convert strings containing date and time expressions to the Date type. The final line of code shows how the constructor method can be used to initialize a date by supplying parameters for the year, month, and day.

Depending ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required