Groups | Blog | Home
all groups > c# > february 2008 >

c# : Format date to convert into words


weird0
2/24/2008 11:10:09 PM
I have date stored in a DateTime object. I can convert this to a
string by writing:

createdDate.ToString("dd/mm/yy")

Is there anyway, I can format the date in words along with a comma.

So, the date looks something like Dec 8, 2006.

Dont wanna go thur the hassle of writing all the code.

Marc Gravell
2/24/2008 11:29:05 PM
Standard:
http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx
Custom:
http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx

There are various that might suit - i.e. "D" from standard, or "ddd"
from custom

Roger Frost
2/25/2008 1:59:56 AM
createdDate.ToString("MMMM dd, yyyy")

Recommend reading this for a lot of different format examples:

http://msdn2.microsoft.com/en-us/library/system.datetime.tostring(VS.71).aspx

Hope this helps

--
Roger Frost
"Logic Is Syntax Independent"



[quoted text, click to view]
Marc Gravell
2/25/2008 7:38:34 AM
[quoted text, click to view]


You mean like .ToString("h:mm tt")?

Of course, you could use "t" or ToShortTimeString() [etc] to get what
the user chooses as their time format

Jon Skeet [C# MVP]
2/25/2008 7:41:20 AM
[quoted text, click to view]

Is it so hard to call dt.ToString("h:mm tt")?

If this happens to be a format you want to use frequently, stick it
into a constant. Don't forget that lots of people want subtly
different formats - and different formats are preferred in different
international contexts.

clintonG
2/25/2008 9:19:42 AM
You'd think there would be an easy way to just get a time returned as 9:00
am for example.

[quoted text, click to view]
clintonG
2/25/2008 4:47:31 PM
Hey guys, thanks for helping me stay lazy this afternoon :-) now I won't
have to slog my way through the docs.


[quoted text, click to view]
Mihai N.
2/25/2008 9:06:12 PM
[quoted text, click to view]
You should go with a standard format (see Marc's answer).
That is culture-sensitive (the right thing), while using
an explicite patern will result in an American format
(even if the culture is French, and the month name,
is French, for example)


--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Roger Frost
2/26/2008 12:01:45 AM

Noted, Thank you.

--
Roger Frost
"Logic Is Syntax Independent"



[quoted text, click to view]
AddThis Social Bookmark Button