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); Console.Read(); 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!
advertisement
advertisement
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.
Next Steps:
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Apply for C# Internship
- Practice Computer Science MCQs
- Buy MCA Books
- Buy C# Books
- Apply for Computer Science Internship