C# Program to Display Date in String


This is a C# Program to display date in string.

Problem Description

This C# Program Displays Date in String.

Problem Solution

Here the date is displayed and month, day and year are separately displayed.

Program/Source Code

Here is source code of the C# Program to Display Date in String. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

 * C# Program to Display Date in String
using System;
namespace DateAndTime
    class Program
        static int Main()
            DateTime date = new DateTime(2013,6, 23);
            string strDate = date.ToString("M");
            Console.WriteLine("Date and Time  :  {0}", date);
            Console.WriteLine("Month and Date :  {0}", strDate);
            return 0;
Program Explanation

This C# program is used to display date in string. The DateTime() function is used to display the date and month, day and year are printed separately.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
Runtime Test Cases
Date and Time  : 6/23/2013 12:00:00 AM
Month and Date : June 23

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.