Q:

Write a program in C# Sharp to find the First day of next month against a given date

0

Write a program in C# Sharp to find the First day of next month against a given date.

Test Data:
Input the Day : 16
Input the Month : 06
Input the Year : 2016
Expected Output :

The formatted Date is : 16/06/2016                                     
The first day of the next month for the above date is: 01/07/2016

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;

class dttimeex56
{
    static void Main()
    {
	int yr,mn,dt;
    Console.Write("\n\n Find the first day of the next month against a given date :\n");
	Console.Write("----------------------------------------------------------------\n");
	
	Console.Write(" Input the Day : ");
    dt = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Month : ");
    mn = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Year : ");
    yr = Convert.ToInt32(Console.ReadLine());		
	DateTime d = new DateTime(yr, mn, dt);
	Console.WriteLine(" The formatted Date is : {0}",d.ToString("dd/MM/yyyy"));
	Console.WriteLine(" The first day of the next month for the above date is : {0}\n", FirstDayOfNextMonth(d).ToString("dd/MM/yyyy"));
    }
    public static DateTime FirstDayOfNextMonth(DateTime dt)
    {
        DateTime ss= new DateTime(dt.Year, dt.Month, 1);
		return ss.AddMonths(1);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now