[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Get a date in relation to another in C#

Posted on 2011-10-11
Medium Priority
Last Modified: 2012-05-12
I need a programmatic way to get the previous sunday and the following saturday dates when given a date, For example if I have the date today 11/10/2011 my code would return,

Sunday 09/10/2011
Saturday 15/10/2011
Question by:Blowfelt82
LVL 53

Accepted Solution

Dhaest earned 2000 total points
ID: 36949455
Something like this...

DateTime dtPrevSunday = DateTime.Now;
while(dtPrevSunday.DayOfWeek != DayOfWeek.sunday) dtPrevSunday = dtPrevSunday.AddDays(-1);

DateTime dtNextSaturday = DateTime.Now;
while(dtNextSaturday.DayOfWeek != DayOfWeek.saturday) dtNextSaturday = dtNextSaturday.AddDays(-1);

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question