The simplest way would be to use Calendar.GetWeekOfYear
, athough this would require having the year input as well:
Console.WriteLine("Bitte Tag eingeben");
int day = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Bitte Monat eingeben");
int month = Convert.ToInt32(Console.ReadLine());
DateTime dt = new DateTime(2019, month, day);
CultureInfo culture = CultureInfo.CurrentCulture;
CalendarWeekRule cwr = culture.DateTimeFormat.CalendarWeekRule;
DayOfWeek dow = culture.DateTimeFormat.FirstDayOfWeek;
int weekOfYear = culture.Calendar.GetWeekOfYear(dt, cwr, dow);
Having said this it wouldn't be too hard to construct a manual calculation with the absence of the year (with the assumption it isn't a leap year):
// Construct an array, with month as index and days as value
int[] monthDays = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// Count the number of days up to the given month
int days = 0;
for (int i = 0; i < month - 1; i++)
{
days += monthDays[i];
}
// Add the given number of days
days += day
// Divide by 7 to get the week of the year
int weekOfYear = (int)Math.Ceiling((double)days / 7);
Of course, if it is a leap year you will need to amend the array to have new int[] { 31, 29, ...
.