Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Dim dt As Date = Date.Today

MsgBox(dt)
like image 662
Ravikant Upadhyay Avatar asked Jul 09 '13 10:07

Ravikant Upadhyay


1 Answers

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.

like image 140
Tim Schmelter Avatar answered Oct 19 '22 14:10

Tim Schmelter