-2

first of all I try to make a class and then make a database via add-migration Initial and update-database . I wrote the class below and the soustraction DateTime.Now - SoldPr below is didn't recognized. Recognized means : Argument 1 of DateTime.Now - SoldPr : impossible conversion of 'System.TimeSpan' to 'decimal' [Test_Dev]csharp(CS1503).

I don't know to solve this problem.

public class Change 
    {
            public DateTime SoldPr { get; set; }
            public int RAF{
               get
                {
                    if(SoldPr.Year > 0 )
                    {
                     return(int) Math.Floor(DateTime.Now - SoldPr).Days;
                    }
                    else
                    {
                        return 0;
                    }
                }                    
            }
    }

Thanks in advance

Sylvain
  • 43
  • 8
  • can you please be more specific? it's quite unclear what exactly you mean by "is didn't recognized"... please refer to [what's on topic](https://stackoverflow.com/help/on-topic) and [how to ask a good question](https://stackoverflow.com/help/how-to-ask). – Franz Gleichmann Jul 17 '21 at 18:08
  • 2
    Probably you want that **Days** to be inside the parenthesys. Subtracting two dates returns a Timespan but you can pass it to the Math.Floor. You pass a double or a decimal – Steve Jul 17 '21 at 18:09
  • Does this answer your question? [Subtracting two dates](https://stackoverflow.com/questions/10871755/subtracting-two-dates) – sticky bit Jul 17 '21 at 18:09

1 Answers1

1

Wha you probably want is:

return (int)Math.Floor((DateTime.Now - SoldPr).TotalDays);
nvoigt
  • 75,013
  • 26
  • 93
  • 142