Tom Knowlton
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(DateT ime 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
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(DateT
{
???
}
}//end of class
//calling code....
CreateDateRange cdr = new CreateDateRange();
cdr.CreateRangeGivenDate("
//cdr.FromDate would now equal 12/20/2009
//cdr.ToDate would now equal 12/22/2009
cdr.CreateRangeGivenDate("
//cdr.FromDate would now equal 12/20/2009
//cdr.ToDate would also equal 12/20/2009
cdr.CreateRangeGivenDate("
//cdr.FromDate would now equal 12/20/2009
//cdr.ToDate would equal 12/26/2009
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.