Most of the programs require the implementation of date functions that return the current date and time. Dates have become such an integral part of daily life that it is easy to operate with them without thinking. VB.Net also includes powerful date arithmetic features that make it simple to manipulate dates.
Date values, time values, and the date and time values can all be found in the Date data type. The date has the default value of 0:00:00 (midnight) on January 1, 0001. System.DateTime is the.NET data type counterpart.
The DateTime structure represents a point in time, which is commonly stated as a date and time of day.
Declaration
<SerializableAttribute> _
Public Structure DateTime _
Implements IComparable, IFormattable, IConvertible, ISerializable,
IComparable(Of DateTime), IEquatable(Of DateTime)
The current date and time can be obtained from the DateAndTime class.
The DateAndTime module contains the properties and procedures which are used in date and time operations.
'Declaration
<StandardModuleAttribute> _
Public NotInheritable Class DateAndTime
A list of properties and methods of DateTime Structure can be obtained from Microsoft documentation.
Create a DateTime Object
A DateTime object can be created in one of the following ways:
- By using any of the overloaded DateTime constructors to invoke a DateTime function Object() { [native code] }.
- Passing a date and time value returned by a property or method to the DateTime object.
- Passing a date and time value's string representation.
- By invoking the implicit default function Object() { [native code] } of the DateTime structure.
Formatting Date
Date literals should be contained by hash signs (# #) and supplied in the format M/d/yyyy, for example, #10/16/2021#. Otherwise, depending on the locale in which your application is running, your code may change.
To convert a Date literal to your locale's or a custom format, use the String class's Format function, giving either a predefined or user-defined date format.
A list of properties and methods of DateAndTime Class, pre-defined, and user-defined Date and Time Format can be obtained from Microsoft documentation.