Как я могу проверить, находится ли DateTime между определенным диапазоном дат, не принимая во внимание год? ⇐ C#
Как я могу проверить, находится ли DateTime между определенным диапазоном дат, не принимая во внимание год?
I'm cognitively struggling with a probably fairly simple problem. Given a certain DateTime, how can I verify that this date (without accounting its year) is in between two other dates?
An example:
DateTime toCheck = new DateTime(1900, 3, 4); DateTime min = new DateTime(2024, 1, 1); DateTime max = new DateTime(2024, 12, 31); // True - 'toCheck' is between 'min' and 'max' In the snippet above, toCheck is in between min and max because 3rd April is between 1st January and 31st December. I can easily verify this with something like new DateTime(min.Year, toCheck.Month, toCheck.Day) >= min && new DateTime(max.Year, toCheck.Month, toCheck.Day)
Источник: https://stackoverflow.com/questions/781 ... t-taking-t
I'm cognitively struggling with a probably fairly simple problem. Given a certain DateTime, how can I verify that this date (without accounting its year) is in between two other dates?
An example:
DateTime toCheck = new DateTime(1900, 3, 4); DateTime min = new DateTime(2024, 1, 1); DateTime max = new DateTime(2024, 12, 31); // True - 'toCheck' is between 'min' and 'max' In the snippet above, toCheck is in between min and max because 3rd April is between 1st January and 31st December. I can easily verify this with something like new DateTime(min.Year, toCheck.Month, toCheck.Day) >= min && new DateTime(max.Year, toCheck.Month, toCheck.Day)
Источник: https://stackoverflow.com/questions/781 ... t-taking-t
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение