Question : datediff -- 2 dates are returning the same datefiff value (i.e. 0)

not sure why I am getting 2 dates coming back with a '0' value -- for example, to day I have 2 records with todays and tomorrows date -- both are returning '0' day difference.


e.Row.Cells[4].Text format ::   {0:dd-MMM-yy}
serverTime format :: datetime
Code Snippet:
1:
2:
DateTime serverTime = service.GetServerTime();
                Int32 dayDiff = Convert.ToDateTime(e.Row.Cells[4].Text).Subtract(serverTime).Days;

Answer : datediff -- 2 dates are returning the same datefiff value (i.e. 0)

Well, I don't know about the datagrid, but you have two options:

1. Exclude the time portion of the date in your filtering mechanism
2. Exclude the time portion of the date in your SQL query.

I'm assuming that the row data does not include the time. In this case, this might work:

DateTime st = service.GetServerTime()
DateTime serverTime = new DateTime((int)st.Year, (int)st.Month, (int)st.Day);
Int32 dayDiff = Convert.ToDateTime(e.Row.Cells[4].Text).Subtract(serverTime).Days;

That will take the absolute date, excluding any time portion.

Alternatively, pass "tomorrows" date into the SQL procedure and select ... WHERE datefield < @tomorrowsDate
Random Solutions  
 
programming4us programming4us