Jack
Jack

Reputation: 10037

.Net: DateTime String format

I'm trying to add a timestamp to a file. However the DateTime Format ToString() looks weird to me.

Here is my code:

Dim _timeStamp As String = Date.Now.ToString("dd_mm_yyyy")

but the value looks like this:

_timeStamp = "03_24_2009"

I checked my PC and the current date is correct. Shouldn't the value look like this: 03_03_2009?

Upvotes: 0

Views: 591

Answers (6)

Rex M
Rex M

Reputation: 144122

For 2-digit month number, use MM not mm. Captial M's refer to month, lowercase m's refer to minutes.

Also, John Sheehan has a nice cheat-sheet for such things.

Upvotes: 15

Inferis
Inferis

Reputation: 4662

I always get this right thanks to my mnemonic:

Months are larger than minutes, "MM" is larger than "mm"

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500675

As others have said, "mm" means minutes and "MM" means months.

I find these MSDN pages useful:

There are also various cheat sheets available on the web. I know I've seen a few of them around, but I only remember my own DZone refcard which includes it (also on Scribd).

EDIT: As mentioned in the comments, John Sheehan has one too. Given that they're all free, why not download everything you can find and keep the one you find most useful? :)

Upvotes: 5

Scott Vander Molen
Scott Vander Molen

Reputation: 6439

mm is minutes. You want MM for months.

Upvotes: 2

eglasius
eglasius

Reputation: 36037

use MM, mm is for minutes

Upvotes: 2

overslacked
overslacked

Reputation: 4137

Try using MM for month. The .ToString is case-sensitive, and lowercase means minutes.

Upvotes: 4

Related Questions