Display date in dd/mm/yyyy format in vb.net

Ravikant Upadhyay picture Ravikant Upadhyay · Jul 9, 2013 · Viewed 319.2k times · Source

I want to display date in 09/07/2013 format instead of 09-jul-13.

Dim dt As Date = Date.Today

MsgBox(dt)

Answer

Tim Schmelter picture Tim Schmelter · Jul 9, 2013

First, uppercase MM are months and lowercase mm are minutes.

You have to pass CultureInfo.InvariantCulture to ToString to ensure that / as date separator is used since it would normally be replaced with the current culture's date separator:

MsgBox(dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture))

Another option is to escape that custom format specifier by embedding the / within ':

dt.ToString("dd'/'MM'/'yyyy")

MSDN: The "/" Custom Format Specifier:

The "/" custom format specifier represents the date separator, which is used to differentiate years, months, and days. The appropriate localized date separator is retrieved from the DateTimeFormatInfo.DateSeparator property of the current or specified culture.