Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting MMDDYYYY to 01-JAN-YY

I have a string in the format in = "01012012". I want it to convert to: 01-JAN-12. How do I achieve it in C#?

like image 857
RG-3 Avatar asked Oct 01 '12 02:10

RG-3


People also ask

How do I convert date to MMM yy in Excel?

Your answer First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.

How do you convert MM DD to YYYY datetime?

yyyy-mm-dd stands for year-month-day . We can convert string format to datetime by using the strptime() function. We will use the '%Y/%m/%d' format to get the string to datetime.


1 Answers

DateTime dateTime = DateTime.ParseExact("01012012", "MMddyyyy", CultureInfo.InvariantCulture);
string newDateString = dateTime.ToString("dd-MMM-yy");

EDIT: Changed output to 2 digit date (instead of 4)

like image 60
Adam Plocher Avatar answered Oct 20 '22 17:10

Adam Plocher