I want to format today's date like this dd/mm/yyyy Please help me

Dani AI

Generated

Short answer: use the format string dd/MM/yyyy — capital MM is month, lowercase mm is minutes (a very common gotcha). and were correct to flag the capitalization. (learn.microsoft.com)

Be aware of culture effects: the standard d short-date specifier (what ToString("d") uses) maps to the current culture's short-date pattern, so its output varies by locale (as and discussed). Also, the / in a custom format string is the culture-specific date separator (so dd/MM/yyyy may render with - or . on some machines unless you control the culture). To force a stable result, pass an explicit format provider (for example, CultureInfo.InvariantCulture) to ToString. (learn.microsoft.com)

Example (VB.NET): a compact, culture-stable way to produce dd/MM/yyyy:

Dim s As String = DateTime.Now.ToString("dd'/'MM'/'yyyy", System.Globalization.CultureInfo.InvariantCulture)
Debug.WriteLine(s)

For persisting or exchanging dates, prefer an unambiguous format (ISO yyyy-MM-dd or the round-trip standard "o") rather than relying on a localized short date. These practices avoid the minute-vs-month mistake and culture surprises that showed up earlier in the thread. (learn.microsoft.com)

Recommended Answers

All 8 Replies

Dim thisDate1 As Date = Now
Debug.Writeline(thisDate1.ToString("dd/mm/yyyy"))

As daniel955 says, you should watch that capitalisation, "mm" is actually minutes in VB.NET as in "hh:mm:ss" e.g. "28/10/2013 11:30:44" is "dd/MM/yyyy hh:mm:ss" but if you had converted this date to "dd/mm/yyyy" you would get this string "28/30/2013" (28th day, 30 minutes, year 2013)

Dim Date1 As DateTime = DateTime.Now()
Debug.Writeline(Date1.ToString("d"))

Hi Xerohomicide,

Doesn't the .Tostring("d"), (short date) depend on your system locale settings?

Sub Main()

    ' Use current time.


' ... Use a format.
' ... Write to console.
Dim time As DateTime = DateTime.Now
Dim format As String = "MMM ddd d HH:mm yyyy"
Console.WriteLine(time.ToString(format))
End Sub

May Tue 18 16:46 2010

Dim thisDate1 As Date = Now
Debug.Writeline(thisDate1.ToString("dd/mm/yyyy"))

KimberGariando see earlier postings mm gives minutes not month (MM)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.