1DateTime dt = DateTime.Now;//Current Time2 3DateTime startweek = dt. AddDays (1-Convert.ToInt32 (dt. Dayofweek.tostring ("D")));//this Monday4DateTime Endweek = Startweek.adddays (6);//this Sunday5 6DateTime startmonth = dt. AddDays (1-DT. Day);//Early this month7DateTime Endmonth = startmonth.addmonths (1). AddDays (-1);//Month End8 9DateTime startquarter = dt. AddMonths (0-(dt. Month-1) %3). AddDays (1-DT. Day);//At the beginning of the quarterTenDateTime Endquarter = startquarter.addmonths (3). AddDays (-1);//At the end of the quarter One ADateTime startyear =NewDateTime (dt. Year,1,1);//early this year -DateTime endyear =NewDateTime (dt. Year, A, to);//End of year
DateTime date Formatting
1DateTime.Now.ToString ();//2016/5/9 13:09:55 Short Date long time2DateTime.Now.ToString ("D");//2016/5/9 Short Date3DateTime.Now.ToString ("D");//May 9, 2016 long date4DateTime.Now.ToString ("F");//May 9, 2016 13:09 short time long Date5DateTime.Now.ToString ("F");//May 9, 2016 13:09:55 long date long time6DateTime.Now.ToString ("g");//2016/5/9 13:09 Short Date short time7DateTime.Now.ToString ("G");//2016/5/9 13:09:55 Short Date long time8DateTime.Now.ToString ("T");//13:09 short time9DateTime.Now.ToString ("T");//13:09:55 Long hoursTenDateTime.Now.ToString ("m");//May 9 OneDateTime.Now.ToString ("M");//May 9 ADateTime.Now.ToString ("R");//Mon, 13:09:55 GMT -DateTime.Now.ToString ("R");//Mon, 13:09:55 GMT -DateTime.Now.ToString ("y");//May 2016 theDateTime.Now.ToString ("Y");//May 2016
C # gets this week, month, year, etc time and datetime date formatting based on the current time