Avatar of metropia
metropia
Flag 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!
ASP.NETC#

Avatar of undefined
Last Comment
Anuradha Goli

8/22/2022 - Mon
Frosty555

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
Frosty555

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy