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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s