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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 115
  • Last Modified:

get midnight of the firts day of week

How do I get datetime for first day of the week, i.e. midnight in C#.
0
johnson1
Asked:
johnson1
  • 2
1 Solution
 
Fernando SotoCommented:
Hi johnson1;

This code snippet should return the value you are looking for.

// This returns the date and time of current day midnight
DateTime rightNow = DateTime.Today;
// Gets midnight of the firts day of this week.
DateTime firstDayOfThisWeek = rightNow.AddDays(-((int)rightNow.DayOfWeek));

Open in new window

0
 
johnson1Author Commented:
thank you.
0
 
Fernando SotoCommented:
Not a problem johnson1, glad I was able to help.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now