VB.Net

VB.Net Date & Time

VB.Net Date & Time

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.

Top course recommendations for you

    Java Applications
    1 hrs
    Beginner
    8.6K+ Learners
    4.44  (369)
    Python List
    1 hrs
    Beginner
    6.2K+ Learners
    4.2  (635)
    Python Classes
    1 hrs
    Beginner
    11.4K+ Learners
    4.39  (804)
    OOPs in Python
    1 hrs
    Beginner
    16.5K+ Learners
    4.32  (1333)
    Docker Swarm Project
    1 hrs
    Beginner
    861 Learners
    4.44  (27)
    Collections in Java
    3 hrs
    Beginner
    5K+ Learners
    4.46  (374)
    PyCharm for Beginners
    1 hrs
    Beginner
    2.9K+ Learners
    4.39  (161)
    Git Tutorial
    2 hrs
    Beginner
    10.7K+ Learners
    4.55  (830)