I am trying to get the remaining date to two decimal points
code I tried
(Math.Round((Convert.ToDecimal(DateTime.Now - i.dueDate)),2)).ToString()
Error I am getting
Unable to cast object of type ‘System.TimeSpan’ to type ‘System.IConvertible’.
How can i solve this ?
2
Answers
Use this snippet code:
Output:
Subtracting two dates yields a
TimeSpan
which is not directly convertible to a decimal. What value do you want? The number of decimal days? The number of minutes? So you need to be explicit by using the properties of aTimeSpan
(likeTotalDays
):