문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top