JinzNaaz
JinzNaaz

Reputation: 69

How to get the date(incl. day-name like Monday, July 06...) in .NET?

Can any one please tell me how to get the day in .net. I know how to get date as 6/7/2015.But instead i need to get Monday,July 6...

Upvotes: 0

Views: 745

Answers (2)

JinzNaaz
JinzNaaz

Reputation: 69

string dt = DateTime.Today.ToLongDateString();
lblcurrentdate.Text = dt;

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460380

You can use DateTime.ToLongDateString():

string date = DateTime.Today.ToLongDateString();  // Monday, July 06, 2015

From MSDN:

The string returned by the ToLongDateString method is culture-sensitive. It reflects the pattern defined by the current culture's DateTimeFormatInfo object. For example, for the en-US culture, the standard long date pattern is "dddd, MMMM dd, yyyy"; for the de-DE culture, it is "dddd, d. MMMM yyyy"; for the ja-JP culture, it is "yyyy'?'M'?'d'?'". The specific format string on a particular computer can also be customized so that it differs from the standard long date format string.

So this method uses the current culture to determine the LongDatePattern and language, you can use this approach if you want to specify a different culture yourself:

var deCulture = new CultureInfo("de-DE"); // germany
string date = DateTime.Today.ToString(deCulture.DateTimeFormat.LongDatePattern, deCulture);
// Montag, 6. Juli 2015
var jaCulture = new CultureInfo("ja-JP"); // japain
date = DateTime.Today.ToString(jaCulture.DateTimeFormat.LongDatePattern, jaCulture);  
// 2015年7月6日

If you want to build a custom format pattern: Custom Date and Time Format Strings

Upvotes: 5

Related Questions