dotnet-Snippets.com
Snippets: 73 | Registered User: 84 | Visitors online: 36
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Get the first and last day of the given date

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 7854

Description:

Gets the first day of the month from the given date.
Gets the last day of month from the given date.




C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static class Month
{
    /// <summary>
    /// Gets the first day of the month.
    /// </summary>
    /// <param name="givenDate">The given date.</param>
    /// <returns>the first day of the month</returns>
    public static DateTime GetFirstDayOfMonth(DateTime givenDate)
    {
        return new DateTime(givenDate.Year, givenDate.Month, 1);
    }

    /// <summary>
    /// Gets the last day of month.
    /// </summary>
    /// <param name="givenDate">The given date.</param>
    /// <returns>the last day of the month</returns>
    public static DateTime GetTheLastDayOfMonth(DateTime givenDate)
    {
        return GetFirstDayOfMonth(givenDate).AddMonths(1).Subtract(new TimeSpan(1, 0, 0, 0, 0));
    }
}


This Snippets could be interesting for you:
No results available

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)