I need to convert "28/08/2012" to MM/dd/YYYY
format that means "08/28/2012".
How can I do that?
I am using below code , but it threw exception to me.
DateTime.ParseExact("28/08/2012", "ddMMyyyy", CultureInfo.InvariantCulture)
There is a formula that can quickly convert dd/mm/yyyy to mm/dd/yyyy date format. Select a blank cell next to the dates you want to convert, type this formula =DATE(VALUE(RIGHT(A9,4)), VALUE(MID(A9,4,2)), VALUE(LEFT(A9,2))), and drag fill handle over the cells which need to use this formula.
Select the cells you want to format. Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.
Select the date and time tab. Change date and time>change calendar settings. In the format look for English(United States) and select. In abbreviated date and time Choose the option MM/dd/yyyy.
but it threw exception to me
Problem:
Your date contains /
seperator ("28/08/2012"
) and you are not giving that in your date string format ("ddMMyyyy"
).
Solution:
It should be "dd/MM/yyyy"
.
This way
DateTime.ParseExact("28/08/2012", "dd/MM/yyyy", CultureInfo.InvariantCulture)
.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
After doing that we will receive a DateTime object with your populated dates which is transferred to string using .ToString()
with desired date format "MM/dd/yyyy"
and optional culture info CultureInfo.InvariantCulture
.
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