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.8K+ Learners
    4.38  (452)
    Python List
    1 hrs
    Beginner
    6.4K+ Learners
    4.21  (666)
    Python Classes
    1 hrs
    Beginner
    11.7K+ Learners
    4.4  (882)
    OOPs in Python
    1 hrs
    Beginner
    16.7K+ Learners
    4.32  (1413)
    Docker Swarm Project
    1 hrs
    Beginner
    879 Learners
    4.56  (36)
    Collections in Java
    3 hrs
    Beginner
    5.1K+ Learners
    4.42  (478)
    PyCharm for Beginners
    1 hrs
    Beginner
    3K+ Learners
    4.41  (175)
    Git Tutorial
    2 hrs
    Beginner
    10.9K+ Learners
    4.54  (919)