Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果用户在过去10天内已注册,请采取措施_C#_Datetime - Fatal编程技术网

C# 如果用户在过去10天内已注册,请采取措施

C# 如果用户在过去10天内已注册,请采取措施,c#,datetime,C#,Datetime,我想创造一个条件:如果一个用户在过去10天内注册了,那么做些什么 var user = new User(); DateTime time = new DateTime(0); if (user.RegisteredAt < time) { DataAp.Fill(dt); dgRecent.ItemsSource = dt.DefaultView;

我想创造一个条件:如果一个用户在过去10天内注册了,那么做些什么

var user = new User();
            DateTime time = new DateTime(0);
            if (user.RegisteredAt < time)
            {
                DataAp.Fill(dt);
                dgRecent.ItemsSource = dt.DefaultView;
                DataAp.Update(dt);
            }

            else
            {
                MessageBox.Show("No Orders in last 10 days ");
            }
var user=new user();
日期时间=新的日期时间(0);
if(user.RegisteredAt<时间)
{
数据ap.Fill(dt);
dgRecent.ItemsSource=dt.DefaultView;
数据更新(dt);
}
其他的
{
MessageBox.Show(“过去10天没有订单”);
}
您的支票应该是:

if((DateTime.Now - user.RegisteredAt).TotalDays < 10)
if((DateTime.Now-user.RegisteredAt).TotalDays<10)

减去两个
DateTime
对象将得到一个
TimeSpan
,您可以使用它的属性来获得天数的差值

我想给你一个答案,但是你没有问一个问题…那么问题是什么?你需要在这里提供更多的上下文。除非读心术的人遇到这个问题,否则没有人会知道你的价值观是什么或你的方法是什么……哈比卜是读心术的人!这解释了很多!:)
Days
就足够了。@TimSchmelter,我从来不知道有
Days
属性:)