How to convert only the date without time to a string in VB.NET

1 Answer

0 votes
Imports System

Module Program

    ' Convert a Date (DateTime) to a string (YYYY-MM-DD)
    Function DateToString(d As Date) As String
        Return d.ToString("yyyy-MM-dd")
    End Function

    ' Build a Date from integers
    Function MakeDate(y As Integer, m As Integer, d As Integer) As Date
        Return New Date(y, m, d)
    End Function

    Sub Main()

        ' Today's date
        Dim today As Date = Date.Today
        Console.WriteLine("Today's date is: " & DateToString(today))

        ' Hard-coded date
        Dim myDate As Date = MakeDate(2025, 12, 7)
        Console.WriteLine("Hard-coded date is: " & DateToString(myDate))

    End Sub

End Module



' run:

' Today's date is: 2026-05-30
' Hard-coded date is: 2025-12-07
'

 



answered 1 hour ago by avibootz

Related questions

...