WebJan 2, 2012 · You can simply write an extension method to DateTime public static int GetQuarter (this DateTime date) { if (date.Month >= 4 && date.Month <= 6) return 1; else if (date.Month >= 7 && date.Month <= 9) return 2; else if (date.Month >= 10 && date.Month <= 12) return 3; else return 4; } and use it as WebMar 25, 2024 · The ( (int)today.DayOfWeek) expression converts the DayOfWeek value to its equivalent integer value. The - ( (int)today.DayOfWeek) + 1 expression calculates the …
How to get date of next coming specific day in C#
WebHere's an example: csharppublic static bool IsInSameWeek(DateTime date1, DateTime date2) { // Get the calendar for the current culture Calendar calendar = CultureInfo.CurrentCulture.Calendar; // Check if the two dates have the same year and week number return date1.Year == date2.Year && calendar.GetWeekOfYear(date1, … WebApr 5, 2024 · DateTime today = DateTime.Today; int currentDayOfWeek = (int) today.DayOfWeek; DateTime sunday = today.AddDays (-currentDayOfWeek); DateTime monday = sunday.AddDays (1); // If we started on Sunday, we should actually have gone *back* // 6 days instead of forward 1... if (currentDayOfWeek == 0) { monday = … trihealth human resources address
c# - How to get previous day using datetime - Stack Overflow
WebApr 3, 2024 · C# Code DayOfWeek currentDay = DateTime.Now.DayOfWeek; int daysTillCurrentDay = currentDay - DayOfWeek.Monday; DateTime … WebMay 12, 2010 · DateTime baseDate = DateTime.Today; var today = baseDate; var yesterday = baseDate.AddDays (-1); var thisWeekStart = baseDate.AddDays (- (int)baseDate.DayOfWeek); var thisWeekEnd = thisWeekStart.AddDays (7).AddSeconds (-1); var lastWeekStart = thisWeekStart.AddDays (-7); var lastWeekEnd = … WebDec 27, 2024 · Then we convert those inputs into proper date and show the to the user. Then we get current culture from System.GlobalizationCultureInfo. Please check official … trihealth hub