0

My problem: I need to get date format as "mm/dd/yyyy"

Scenario:

I have declared DateBirth as nullable DateTime.

The value I get when I use:

AdvancedObj.DateBirth .Value.ToString()

is: "13/03/2013 00:00:00"

The value I get when I use

AdvancedObj.DateBirth .Value.ToString(CultureInfo.InvariantCulture)

is :"03/13/2013 00:00:00"//This is roughly correct but, I do not need 00:00:00

I have tried this as well, but the format is correct and value is incorrect.

AdvancedObj.DateBirth.Value.ToString("dd/mm/yyyy",CultureInfo.GetCultureInfo("en-Us"))


 **"13/00/2013"**

Can anybody point me, what am I missing?

2
  • 3
    mm is minutes. You want MM for months. Commented Apr 9, 2013 at 12:34
  • When using a custom date format, there is no need for a Culture. The formatting wildcard for a double-digit month is actually an uppercase "MM", thus: "dd/MM/yyyy" Commented Apr 9, 2013 at 12:35

2 Answers 2

2

Use the right format string for months - it is MM. mm is for minutes:

AdvancedObj.DateBirth.Value.ToString("MM/dd/yyyy",CultureInfo.InvariantCulture)

Also, order them correctly as above - if you want months before days, use MM/dd/yyyy, if the other way around, dd/MM/yyyy.

I suggest you take a good long read of Custom Date and Time Format Strings on MSDN.

Sign up to request clarification or add additional context in comments.

1 Comment

I have not observed 'm' carefully in MSDN. Was trying for it for a hour!. Thank you.
1

Month are 'M'. 'm' is for minutes.

"dd/MM/yyyy"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.