tags:

views:

226

answers:

6

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?

+15  A: 

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.

Rex M
Handy cheat sheet: http://john-sheehan.com/blog/net-cheat-sheets/
John Sheehan
+4  A: 

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

overslacked
+2  A: 

use MM, mm is for minutes

eglasius
+2  A: 

mm is minutes. You want MM for months.

Scott
+5  A: 

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? :)

Jon Skeet
Jon, I've put those pages into a cheat sheet: http://john-sheehan.com/blog/net-cheat-sheets/
John Sheehan
@John: So have I, effectively - see the edit I was making when you commented :) I'll add your link too.
Jon Skeet
+1  A: 

I always get this right thanks to my mnemonic:

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

Inferis