"Getting incorrect results while using ToString("dd/mm/yyyy") "
In this article I am sharing one of the issue I got stuck in.
Please go through the following code :
string date = "30,jun,2015";
DateTime dt = Convert.ToDateTime(date);
string date1 = dt.ToString("dd/mm/yyyy");
The code looks absolutely fine but this code may give you some unexpected results such as:
30/54/2015 or 30/45/2015, etc .
This is because mm in "dd/mm/yyyy" represents the minutes and not the month.
Inorder to get the month we have to use "dd/MM/yyyy". This will give you the actual month values.
Happy Coding....
0 Comment(s)