Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to String.Format the day of the month in c#?

DateTime's formatting has some overlap between it'a standard date and time formatting strings and some of it's custom format specifier by them selves. As a result, when I evalate this expression:

string.Format(">{0:d}< >{0: d}<", DateTime.Now)

and get this result:

>8/3/2009< > 3<

My question is: How do I get String.Format to output just the day of the month (using the d format) without any surrounding spaces?

like image 446
BCS Avatar asked Dec 13 '22 03:12

BCS


2 Answers

use "{0:%d}": reference

like image 164
BCS Avatar answered Dec 16 '22 18:12

BCS


I keep this page in my favorites...

http://blog.stevex.net/index.php/string-formatting-in-csharp/

Saves me all the time.

like image 31
Jeffrey Hines Avatar answered Dec 16 '22 17:12

Jeffrey Hines