要求只判断年月日,如上图正在根据dateTimePicker1控件的时间进行搜索

解决方案 »

  1.   


     this.dateTimePicker1.CustomFormat ="yyyy-MM-dd";
                this.dateTimePicker1.Format= System.Windows.Forms.DateTimePickerFormat.Custom;
                string s = this.dateTimePicker1.Text;
      

  2.   

    if (dataTimePicker1.Value == DateTime.Now)
        ...
      

  3.   


            private void button2_Click(object sender, EventArgs e)
            {
                DateTime time1 = new DateTime(2011, 6, 25, 23, 37, 0, DateTimeKind.Local);
                TimeSpan timespan = dateTimePicker1.Value - time1;            if (timespan.Ticks >= 0)
                {
                    MessageBox.Show("Picked time is new");
                }
                else
                {
                    MessageBox.Show("Picked time is old");
                }
            }
      

  4.   

    用C#dateTimePicker1.Value.Date判断好久没用过这个控件了。。也可以用ToString方法格式化字符串。。再比较
      

  5.   

    要看你入住时间,数据库存储的是什么格式,如果是 2011-01-01,就像我那么写就可以得到 dateTimePicker1选择的年月日了然后 
    this.dateTimePicker1.CustomFormat ="yyyy-MM-dd";
    this.dateTimePicker1.Format= System.Windows.Forms.DateTimePickerFormat.Custom;
    string s = this.dateTimePicker1.Text;//拼写查询SQL 
    string strSql = " select * from table1 where 入住时间= '"+ s+"';";
    //执行查询,填充到DataSet 里执行数据库查询,返回 DataSet  ds datagrid1.DataSouce = ds.Table[0];
      

  6.   


    MessageBox.Show(dateTimePicker1.Value.ToShortDateString());