Question

I have a DateTime in format mm/dd/yyyy and I need to get string that would be looks like "yyyy-mm".

I know, that I can use ToString() with fomat inside, but for my format it doesn't work.

For this DateTime: 1/31/1999 12:00:00 AM

I got this: "1999-00" string using ToString("yyyy-mm")

Was it helpful?

Solution

you want ToString("yyyy-MM")

mm is used for minutes. For months:

M - The month, from 1 through 12.

MM - The month, from 01 through 12.

MMM - The abbreviated name of the month.

MMMM - The full name of the month.

See here for all formats

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top