Posted by: tzuhsun | January 17, 2009

Display forward slash (’/’) in date using C#

Still remember my previous post ? Display forward slash (’/’) in date under VB6

I face the same issue in C#, however the solution this time is slightly different with solution in VB6.

//
//   First solution : surround the desired date seperator
//   ('/' in this case) with single quote.
//
string date = DateTime.Today.Date.ToString("dd'/'M'/'yyyy");

//
//   Second solution : same like solution in VB6,
//   except add '@' in front of the string.
//
string date = DateTime.Today.Date.ToString(@"dd\/MM\/yyyy");

Referencehttp://authors.aspalliance.com/aspxtreme/sys/demos/datetimeformats.aspx

Keyword: Date seperator, date format, date pattern, C#, .Net, forward slash


Leave a response

Your response:

Categories