Getting Start Date of current Month in C#

In this article, I would like to show the Start Date of current Month with Now property in C#.
  • 2574

In this article, I would like to show the Start Date of current Month with Now property in C#. To do that you can use month property with datetime now and today property.

DateTime Now Property

This displays the current date and time of the system, expressed as the local time. In other words the Now property returns a DateTime object that has the date and time values for right now. 

Month Property

This property is used to get month component of the date.

Start Date of current Month

You can do it in C#. The following is simple code for it.

using System;

using System.Collections.Generic;
using
System.Linq;
using
System.Text;

namespace ConsoleApplication71

{
    class Program

    {

        static void Main(string[] args)

        {
 
            Console.WriteLine("Today: {0}", DateTime.Now);

            var today = DateTime.Now;

            var StartDate = new DateTime(today.Year, today.Month, 1);

            Console.WriteLine("Start Date of current Month : {0}", StartDate.ToString("yyy/MM/dd")); 

        }

    }
}


Output


Start-Date-of-Current-Month-in-Csharp.jpg

© 2013 dotNetheaven. All rights reserved.