【发布时间】:2019-01-15 10:31:27
【问题描述】:
如何查找输入中的日期是否在特定日期范围内(例如,过去 7 天,意思是我会说 -7)。如果是在过去 7 天内,做某事,否则做其他事情。
我目前可以做到这一点,但我不知道如何进一步改变它以满足我的需求。
string a = "-1"; // These are values that are configurable based on which date is checked. Yesterday means, -1 for example.
string b = "-15"; // -15 means within last 15 days.
DateTime d = input;
DateTime e = d.AddDays(int.Parse(a));
if (d is between datetime.now and e)
{
//do something
}
else do something
【问题讨论】:
-
C#中没有
between类型操作。您需要执行d >= lowerLimit && d <= upperLimit(替换为<和>,具体取决于范围是独占而不是包含)。 -
@Richard:理查德,伙计,我知道。我写了一个算法,想知道如何把它翻译成 C# 哈哈。我会为您的评论竖起大拇指 :D :D :D
标签: c# .net datetime c#-4.0 compare