Pergunta

In a radGridView, I have 3 columns with the type GridViewDateTimeColumns. I need to subtract two of these columns to get the days difference in the third column.

 radGridView1.Columns["Ritardo"].Expression = "Periodo-Data_Pagam";

I get this error regardless of coding the above line or writing the expression in the designer. The data in the columns "Periodo" and "Data_Pagam" are both from SQL2012 DB dateTime type.

"Cannot perform '-' operation on System.DateTime and System.DateTime

How can I get the difference (days) between the two above date.

Foi útil?

Solução

using DateDiff(Day,StartDate,Enddate) you can suceed this

Outras dicas

If you want day difference by coding then you can use this type of coding also.

DateTime sp1 = DateTime.ParseExact(firstdate, "MMddyyyyHHmm", null);
DateTime ss1 = DateTime.ParseExact(lastdate, "MMddyyyyHHmm", null);
double ts = (ss1 - sp1).Days;

difference will be ts

i am using like this for date diff column, it would be better option by database.. DATEDIFF(day,firstdate,lastdate) AS DiffDate

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top