Get difference between two dates?

Hey @prajakta

well this is due to the date format you are passing.

on your system it might be like MM/dd/yyyy(10/12/2017) better to check date format on your system write line Now.Date.Tostring and check.
and from your excel you are getting like this 12-10-2017 i.e so format mismatching so you are getting wrong or negative result.

if you will do like this it will return you 0.

Convert.ToString((Now.Date - Now.Date).TotalDays) // write line it.

Convert.ToString((Convert.ToDateTime(“10/12/2017”)- Convert.ToDateTime(“10/12/2017”)).Days) //write line it.

this will also return you the 0 days.

Note- you were noticing why i am using .Days in the second line.
well if you will use TotalDays Extension method it will return result as a double and if you will use .Days Extension method it will return you result as an Integer.Both results will be same just the return type is different.
IMO better to use int instead of double :slight_smile:

3 Likes