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#?
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With