Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the day name from a selected date?

Tags:

c#

datetime

I have this : Datetime.Now(); or 23/10/2009
I want this : Friday

For local date-time (GMT-5) and using Gregorian calendar.

like image 942
Jonathan Escobedo Avatar asked Oct 23 '09 19:10

Jonathan Escobedo


People also ask

How do I get the day name for a certain date in Excel?

The easiest way to see the weekday name is to select the cell, then press the Number Format Drop-down menu button on the Home tab of the Ribbon. The Long Date format shows a preview of the date and includes the name of the day for the date in the selected cell.

How do I find the day name from a date?

The DAY function takes just one argument, the date from which you want to extract the day. In the example, the formula is: = DAY ( B5 ) B5 contains a date value for January 5, 2016. The DAY function returns the number 5 representing the day...

Can Excel determine the day of the week from a date?

Summary. The Excel WEEKDAY function takes a date and returns a number between 1-7 representing the day of week. By default, WEEKDAY returns 1 for Sunday and 7 for Saturday, but this is configurable. You can use the WEEKDAY function inside other formulas to check the day of week.


4 Answers

//default locale
System.DateTime.Now.DayOfWeek.ToString();
//localized version
System.DateTime.Now.ToString("dddd");

To make the answer more complete:

  • DayOfWeek MSDN article

  • If localization is important, you should use the "dddd" string format as Fredrik pointed out - MSDN "dddd" format article

like image 172
brendan Avatar answered Nov 01 '22 11:11

brendan


If you want to know the day of the week for your code to do something with it, DateTime.Now.DayOfWeek will do the job.

If you want to display the day of week to the user, DateTime.Now.ToString("dddd") will give you the localized day name, according to the current culture (MSDN info on the "dddd" format string).

like image 27
Fredrik Mörk Avatar answered Nov 01 '22 10:11

Fredrik Mörk


System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetDayName(System.DateTime.Now.DayOfWeek)

or

System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetDayName(DateTime.Parse("23/10/2009").DayOfWeek)
like image 9
Mustafa Gülmez Avatar answered Nov 01 '22 10:11

Mustafa Gülmez


DateTime.Now.DayOfWeek quite easy to guess actually.

for any given date:

   DateTime dt = //....
   DayOfWeek dow = dt.DayOfWeek; //enum
   string str = dow.ToString(); //string
like image 8
Letterman Avatar answered Nov 01 '22 10:11

Letterman