Saturday, March 31, 2012

Subracting days from datetime?

I thought I could subract days from a DateTime instance by passing a negative number into the AddDays method. That doesn't seem to work however. Do I have the syntax right below
(its in c#)
DateTime maxDate = DateTime.Now;
maxDate.AddDays(-1);
// results in no days subtracted, still shows current day. arrrgh.
Does this work?

DateTime maxDate = DateTime.Now;

maxDate.Subtract( new TimeSpan( 24, 0, 0) );
Try: maxDate = maxDate.AddDays(-1);

0 comments:

Post a Comment