How to get previous day using datetime.

Posted by Niike2 on Stack Overflow See other posts from Stack Overflow or by Niike2
Published on 2010-03-22T16:01:15Z Indexed on 2010/03/22 16:01 UTC
Read the original article Hit count: 411

Filed under:
|
|
|

I want to set a DateTime property to previous day at 00:00:00. I don't know why DateTime.AddDays(-1) isn't working. Or why DateTime.AddTicks(-1) isn't working. First should this work?

I have 2 objects. Each object have DateTime fields ValidFrom, ValidTo.

First i save an object with ValidTo using the application setting MaxDate (SQL-server maxdate 9999-12-12). Then when I save a new object and that object ValidFrom is within the first objects ValidFrom - ValidTo timespan I want to change first objects ValidTo datetime to previous day of new objects ValidTo datetime.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET