Aniket Narvankar

Aniket Narvankar

  • 566
  • 2.1k
  • 602.6k

C Sahrp Date Time Functions

Sep 28 2018 7:10 AM
I want current system date in c sharp in this format,
28-SEP-2018,so I write the following code
 
string Day = Convert.ToString(DateTime.Now.Day);
string Year = Convert.ToString(DateTime.Now.Year);
string month = DateTime.Now.ToString("MMM").ToUpper();
string date = Day + "-" + month + "-" + Year;
It is giving me date in required format.Is there any other way this could be done in C Sharp? Before this I used this code
string currentDate = DateTime.Now.ToString("dd-MM-yyyy");
but it give me output as 24-08-2018 

Answers (6)