get midnight of the firts day of week

Posted on 2014-08-23
Last Modified: 2014-08-23
How do I get datetime for first day of the week, i.e. midnight in C#.
Question by:johnson1
    LVL 62

    Accepted Solution

    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


    Author Closing Comment

    thank you.
    LVL 62

    Expert Comment

    by:Fernando Soto
    Not a problem johnson1, glad I was able to help.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now