-5

I am not that much experienced in asp.net MVC. I want to display date in correct format. But it is showing some number instead of that.

Below is my screenshot of the problem.

enter image description here

Here is my code where I convert date.

dateTime[i] = Convert.toDateTime(orderDetail.Rows[i]["joiningDate"].toString());
Surjeet Bhadauriya
  • 6,755
  • 3
  • 34
  • 52
  • This does not seem to be a C# code. Where are these camelCase methods from? Btw here are the date format strings in C#: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings Please note that the string representation of each format can be different per culture. When formatting date and time, always specify the culture to avoid confusion. – György Kőszeg Mar 10 '18 at 10:58
  • That is a json format (refer [this answer](https://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format)) –  Mar 10 '18 at 11:21

2 Answers2

1

use this. you are not getting date in correct format so first convert it into string format and then to date time

Convert.ToDateTime(Convert.ToDateTime(orderDetail.Rows[i]["joiningDate"]).ToString("MM/dd/yyyy"))
Okasha Rafique
  • 672
  • 5
  • 12
0

To convert a date to a proper string, you can use DateTime.ToString(string format)

so:

DateTime.Now.ToString("dd-MM-yyyy")

will display as 10-03-2018.

So on your page you'll have to use .ToString on your date, with the format you want to use.

Dnomyar96
  • 300
  • 3
  • 12
  • This has nothing to do with OP's issue (which is because they are binding to json date value) –  Mar 10 '18 at 11:22