w3resource

C#: Get the day and month name of current date

C# Sharp DateTime: Exercise-49 with Solution

Write a program in C# Sharp to get the day and month of the current date.

Sample Solution:-

C# Sharp Code:

using System; // Importing the System namespace

class dttimeex49 // Declaring a class named dttimeex49
{
    static void Main() // Declaring the Main method
    {
        Console.Write("\n\n Display the month no. and name for the current date :\n"); // Displaying a message in the console
        Console.Write("---------------------------------------------------------\n"); // Displaying a separator line	
        DateTime now = DateTime.Now; // Initializing a DateTime object with the current date and time
        Console.WriteLine(" The current Month No. is : {0} ",now.Month); // Displaying the current month number
        Console.WriteLine(" The current Month is : {0}\n",now.ToString("MMMM")); // Displaying the full name of the current month
    }
}

Sample Output:

 Display the month no. and name for the current date :                                                        
---------------------------------------------------------                                                     
 The current Month No. is : 6                                                                                 
 The current Month is : June

Flowchart:

Flowchart: C# Sharp Exercises - Get the day and month name of current date

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

+

Previous: Write a program in C# Sharp to get the number of days of a given month for a year.
Next: Write a program in C# Sharp to print the name of the first three letters of month of a year starting form current date.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/csharp-exercises/datetime/csharp-datetime-exercise-49.php