This method returns the Month Start - CSharp System

CSharp examples for System:DateTime Month

Description

This method returns the Month Start

Demo Code


using System.IO;/*ww w  . j a va2  s  . c om*/
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        #endregion
            
            #region GetMonthStart(int year = 0, int month = 0)
            /// <summary>
            /// This method returns the Month Start
            /// </summary>
            public static DateTime GetMonthStart(int year = 0, int month = 0)
            {
                // initial value
                DateTime monthStart;

                // locals
                int day = 1;
                int hour = 0;
                int min = 0;
                int sec = 0;

                // update the params for Year and Month if not supplied
                if (year == 0)
                {
                    // Set the value for year
                    year = DateTime.Now.Year;
                }

                // Set the value for month
                if (month == 0)
                {
                    // Set the value for month
                    month = DateTime.Now.Year;
                }

                // now create the monthStart date
                monthStart = new DateTime(year, month, day, hour, min, sec);

                // return value
                return monthStart;
            }
}

Related Tutorials