Error: no overload for "ToString" method takes 1 argument

I am trying to format the date in a specific order

Time = DateTime.Parse(p.Time.ToString("dd-MM-yyyy HH:mm:ss"))

Data Type Time-DateTime

But I get this error:

No overload for the "ToString" method takes 1 argument.

p is the object of the table from which I get the time.

  List<ProductImageMapWrapper> lstpm = new List<ProductImageMapWrapper>();
  lstpm = _db.ProductImageMaps.Where(i => i.ClientId == null && i.BrandId == null).Select(p => new ProductImageMapWrapper
  {
  Time= // Problem here
  }

Now I tried to use it that way

Time = DateTime.Parse(string.Format("{dd-MM-yyyy HH:mm:ss}", p.Time))

but then I got this error:

LINQ to Entities does not recognize the method System.DateTime Parse(System.String), and this method cannot be translated into a storage expression.

+4
source share
7 answers

It seems to me that the Time property of both types (ProductImageMap and ProductImageMapWrapper) is a DateTime. If so, then you should useTime = p.Time

, DateTime . , DateTime . DateTime , .

+1

. . P, .

DateTime.Parse(System.DateTime.Now).ToString("dd-MM-yyyy HH:mm:ss")
+1
String Time = Convert.ToDateTime(p.Time).ToString("dd-MM-yyyy HH:mm:ss");
+1

, , :

string  p = "21-11-2013 11:12:13";              
DateTime time = DateTime.ParseExact(p, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
0

p.Time string , , string DateTime ,

        CultureInfo provider = CultureInfo.InvariantCulture;
        string format = "dd-MM-yyyy HH:mm:ss"; //This should be format that you get in string
        List<ProductImageMapWrapper> lstpm = new List<ProductImageMapWrapper>();
        lstpm = _db.ProductImageMaps.Where(i => i.ClientId == null && i.BrandId == null).Select(p => new ProductImageMapWrapper
        {
            Time = DateTime.ParseExact(p.Time, format, provider)
        });
0

 var selectQuery=from add in db.address
                select add.myDate.toString("{0:dddd, MMMM d, yyyy}");

 selectQuery.Distinct();

.

DateTime time = DateTime.Now;              // Use current time
string format = "MMM ddd d HH:mm yyyy";    // Use this format
Console.WriteLine(time.ToString(format));

1.MMM
2.ddd
3.d MONTH
4.HH 24-
5.
6.yyyy displayfour-digit year

0

DateTime.ToString(format) Nullable.ToString( ):

DateTime? myDate = form.dteStartDate; string sqlFormattedDate = myDate.Value.ToString( "yyyy-MM-dd HH: mm: ss" ); , , . , - :

string sqlFormattedDate = myDate.HasValue 
? myDate.Value.ToString("yyyy-MM-dd HH:mm:ss")
: "<not available>";
0

Source: https://habr.com/ru/post/1523660/


All Articles