如何在 C# 中将我的日期时间选择器与我的电脑的当前日期进行比较?

How to compare my Date time Picker to my pc's current date in C#?

无法将我的 DateTimePicker 与今天减去 18 年的日期进行比较。

我从一个 if 语句开始,但没走多远,所以我尝试使用一种使用 Picker 转换的方法,然后进行比较,但这也不起作用,所以我回到了简单的东西。

(我知道比较当前设置为小于,但我试图在检查选择器已更改后的那一天减去 18 年)

//First check if the datetimepicker was changed

if (dateTimePicker.Value.Date <= DateTime.Now.Date)
  {
        //Second I am trying to figure out how to subtract the date by 18 years so that I can use that result to tell if it goes on with the code.
  }

假设此人输入的日期是 1985 年 5 月 10 日,而今天的日期是 2019 年 6 月 8 日。 它会 return 您已成年等信息。 如果这个人在 2010 年 5 月 10 日输入,它会 return 你太年轻,它不会继续使用我的代码。

var selectedDate = dateTimePicker.Value.Date;
var eligbleDate = DateTime.Now.AddYears(-18).Date; //subtract years to get eligble date
if (selectedDate <= eligbleDate ) {
     ....
}