C# Number of days between two dates problem

Posted by Jamie on Stack Overflow See other posts from Stack Overflow or by Jamie
Published on 2010-05-18T10:59:12Z Indexed on 2010/05/18 11:10 UTC
Read the original article Hit count: 402

Filed under:
|

Hi all,

I have a small problem with the code below, the 'days' variable always seems to be 0 no matter how far apart the days are.

Can you see anything obviously wrong?

        System.TimeSpan span = dates[0] - dates[1]; // e.g. 12/04/2010 11:44:08 and 18/05/2010 11:52:19
        int days = (int)span.TotalDays;

        if (days > 10) //days always seems to be 0
        {
            throw new Exception("Over 10 days");
        }

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about dates