Link to home
Start Free TrialLog in
Avatar of metropia
metropiaFlag for United States of America

asked on

calculate week ending

hi,

I need to calculate the week ending based on a date provided by the user in a asp.net form.

I am using C#. The calculation of the week ending would be placed here:

            if (dt.HasValue)
            {
                Session["Date"] = dt;
                In here <<
            }

Open in new window


Thanks!
Avatar of Frosty555
Frosty555
Flag of Canada image

You can use the DateTime.DayOfWeek property to determine the day of the week.

http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek

Once you know what day of the week it is, it should become clear how many days it is until the end of the week depending on what you define as the end of the week. For example, if "Sunday" is the end of the week, and it currently is "Thursday", then you know that the end of the week is 3 days in the future.

You can advance your date by that many days using the DateTime.AddDays() function, and you should have a datetime set to the end of the week.

http://msdn.microsoft.com/en-us/library/system.datetime.adddays
ASKER CERTIFIED SOLUTION
Avatar of Frosty555
Frosty555
Flag of Canada 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
SOLUTION
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
SOLUTION
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