Hello, to find out the month: look at the following code:
String[] s = DateTime.Now.ToString().Split('-',' ');
for (int i = 0; i < s.Length; i++)
{
switch (i)
{
case 0:
Console.WriteLine("Date is :{0}",s[i]);
break;
case 1:
if(s[i] == "01") Console.WriteLine("Month January");
break;
}
}
I have given you a logic. However this is a very bad and redundant coding. Its just a way so that you can use this to develop your own logic.
Just confirm one thing: print the date time on the console. If you do so you can then decide which condition to write in the switch case.
You need to know how to format and operate on a particular string: i have used string's split method. There are multiple ways just, google them.
Why even do all the above things? simply say :
Console.WriteLine(DateTime.Now.ToString("MM"));
Whats the reason to do all the above exercise? To just develop your logic? What if there was no help. These are all just wrappers. You need to write something of your own. Just grow from the situation.
Thanks,
Happy learning.