I am trying to get todays date in GBR format but,
DateTime.Now.ToString("dd/mm/yyyy");
returns with the value of 08/00/2013
So 00 in the month group was returned instead of returning the month 04.
Any ideas why this happened?
I am trying to get todays date in GBR format but,
DateTime.Now.ToString("dd/mm/yyyy");
returns with the value of 08/00/2013
So 00 in the month group was returned instead of returning the month 04.
Any ideas why this happened?
Lower mm means minutes, so
DateTime.Now.ToString("dd/MM/yyyy");
or
DateTime.Now.ToString("d");
or
DateTime.Now.ToShortDateString()
use MM(months) instead of mm(minutes) :
DateTime.Now.ToString("dd/MM/yyyy");
check here for more format options.
It should be MM for months. You are asking for minutes.
DateTime.Now.ToString("dd/MM/yyyy");
See Custom Date and Time Format Strings on MSDN for details.
In addition to what the other answers have said, note that the '/' character in "dd/MM/yyyy" is not a literal character: it represents the date separator of the current user's culture. Therefore, if the current culture uses yyyy-MM-dd dates, then when you call toString it will give you a date such as "31-12-2016" (using dashes instead of slashes). To force it to use slashes, you need to escape that character:
DateTime.Now.ToString("dd/MM/yyyy") --> "19-12-2016" for a Japanese user
DateTime.Now.ToString("dd/MM/yyyy") --> "19/12/2016" for a UK user
DateTime.Now.ToString("dd\\/MM\\/yyyy") --> "19/12/2016" independent of region
Use MM for months. mm is for minutes.
DateTime.Now.ToString("dd/MM/yyyy");
You probably run this code at the begining an hour like (00:00, 05.00, 18.00) and mm gives minutes (00) to your datetime.
From Custom Date and Time Format Strings
"mm" --> The minute, from 00 through 59.
"MM" --> The month, from 01 through 12.
Here is a DEMO. (Which the month part of first line depends on which time do you run this code ;) )
There are only minor error.Use MM instead of mm ,so it will be effective write as below:
@DateTime.Now.ToString("dd/MM/yyy")