Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Format date to convert into words

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
weird0 - 25 Feb 2008 07:10 GMT
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.

Regards
Marc Gravell - 25 Feb 2008 07:29 GMT
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

Marc
Roger Frost - 25 Feb 2008 07:59 GMT
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

Signature

Roger Frost
"Logic Is Syntax Independent"

> I have date stored in a DateTime object. I can convert this to a
> string by writing:
[quoted text clipped - 8 lines]
>
> Regards
clintonG - 25 Feb 2008 15:19 GMT
You'd think there would be an easy way to just get a time returned as 9:00
am for example.

> createdDate.ToString("MMMM dd, yyyy")
>
[quoted text clipped - 16 lines]
>>
>> Regards
Marc Gravell - 25 Feb 2008 15:38 GMT
> You'd think there would be an easy way to just get a time returned as 9:00
> am for example.

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

Marc
Jon Skeet [C# MVP] - 25 Feb 2008 15:41 GMT
> You'd think there would be an easy way to just get a time returned as 9:00
> am for example.

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.

Jon
clintonG - 25 Feb 2008 22:47 GMT
Hey guys, thanks for helping me stay lazy this afternoon :-) now I won't
have to slog my way through the docs.

> You'd think there would be an easy way to just get a time returned as 9:00
> am for example.
[quoted text clipped - 19 lines]
>>>
>>> Regards
Mihai N. - 26 Feb 2008 05:06 GMT
> createdDate.ToString("MMMM dd, yyyy")
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)

Signature

Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

Roger Frost - 26 Feb 2008 06:01 GMT
Noted, Thank you.

Signature

Roger Frost
"Logic Is Syntax Independent"

>> createdDate.ToString("MMMM dd, yyyy")
> 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)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.