【发布时间】:2011-09-07 04:40:42
【问题描述】:
我使用了 DATEDIFF 函数,但由于它需要 yyyy/mm/dd 这个代码给出了错误的值,因为我在这个格式日、月、dd、yyyy 中存储了日期时间选择器中的日期
private void button3_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
DBHandling db = new DBHandling();
db.GetDataset(" select JoiningDate from Emp where name = '" + textBox2.Text + "'", ref ds);
db.GetDataset(" select LeavingDate from AddDate where name = '" + textBox2.Text + "'", ref ds1);
string date1, date2;
date1 = ds.Tables[0].Rows[0][0].ToString();
date2 = ds1.Tables[0].Rows[0][0].ToString();
db.GetDataset("select DATEDIFF(day,2008/1/15,2008/1/12) ", ref ds2);
textBox5.Text = ds2.Tables[0].Rows[0][0].ToString();
}
那么我应该怎么做才能正确选择两个日期之间的差异,即两个日期之间的天数,提前谢谢
【问题讨论】:
-
这肯定不是纯 C 代码。我猜这是 C#,对吗?
-
重新标记。我们应该有类似“looks-like-c”或“looks-like-java”这样的标签。)
标签: c#