Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Please help with date algorithm

Given any date, I want to subtract days from that date until the date equals a "Sunday".

If executed on a Sunday, the from and to date range would be from Sunday to Sunday:

Sample method calls:

public class DateRange()
{
   public DateRange(){}

  public DateTime fromDate;
  public DateTime toDate;

  public void CreateRangeGivenDate(DateTime tempdt)
{
???
}

}//end of class


//calling code....


CreateDateRange cdr = new CreateDateRange();
cdr.CreateRangeGivenDate("12/22/2009")

//cdr.FromDate would now equal 12/20/2009
//cdr.ToDate would now equal 12/22/2009


cdr.CreateRangeGivenDate("12/20/2009")

//cdr.FromDate would now equal 12/20/2009
//cdr.ToDate would also equal 12/20/2009


cdr.CreateRangeGivenDate("12/26/2009")

//cdr.FromDate would now equal 12/20/2009
//cdr.ToDate would equal 12/26/2009
ASKER CERTIFIED SOLUTION
Avatar of rajeeshmca
rajeeshmca
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial