Get day from DateTime using C#

一曲冷凌霜 提交于 2019-12-05 00:49:05

You are looking for the DayOfWeek property.
Then, as Dan suggests in the comment below, just look at the integer value of the enum to get the day as integer:

int d = (int)System.DateTime.Now.DayOfWeek

DayOfWeek is an Enum. To get the integer instead of the string representation you can cast it

int i = (int)d.DayOfWeek

if you want to find out the name of the day, you can do this as follows:

DateTime.Now.DayOfWeek

Response.Write(DateTime.Now.DayOfWeek);
DateTime.DayOfWeek

Yes DateTime has DayOfWeek() method.

Harry Spruce

I use:

int day = (int)System.DateTime.Now.DayOfWeek;
string dayoftheweek;

In the public partial class Form :

System.Windows.Forms.Form class 

(For a c# winforms application)

 DateTime dt = Convert.ToDateTime (txtMaxDate.Value); /*Store date in dt */
int day = dt.Day; /*Get date as (01-01-2019 then it will give 01 as day)*/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!