该字符串未被识别为有效的datetime 类型
protected void Sureborrow_Click(object sender, EventArgs e){
docid = this.Docidtxt.Text;
userid = this.Useridtxt.Text;
dbname = this.Ddlborrow.SelectedValue;
string borrowdate = (System.DateTime.Now).ToString("yy/mm/dd");
string shredate=borrowdate+00/00/30;
SqlConnection conn = db.createcon();
conn.Open();
SqlCommand cmd=new SqlCommand("insert into Borrowinfo values('"+docid+"','"+userid+"','"+
Convert.ToDateTime(borrowdate) + "','" + Convert.ToDateTime(shredate)+ "','" + dbname + "')", conn);
cmd.ExecuteNonQuery();
conn.Close();
对与string borrowdate = (System.DateTime.Now).ToString("yy/mm/dd");
string shredate=( System.DateTime.Now.AddDays(30)).ToString("yy/mm/dd");
我想实现当前日期borrowdate加上30天,得到另一个日期shredate,但是老是出错
提示:该字符串未被识别为有效的datetime 类型
将上面两句改为:TimeSpan TS = new TimeSpan(30, 0, 0, 0);
DateTime dtime = Convert.ToDateTime(borrowdate);
string shredate=dtime.Add(TS).ToString( "yy/mm/dd ");
仍会出现同样的错误
另外插入数据库的当前日期不是2008/3/24,而是2008/9/24,相差六个月是怎么回事,检查了系统时间设置也没有错
请帮帮忙
--------------------编程问答-------------------- mm是分钟,想显示月份 要用大写 M
--------------------编程问答--------------------
string borrowdate = (System.DateTime.Now).ToString("yy/M/dd");
or
string borrowdate = (System.DateTime.Now).ToString("yy/MM/dd");
该字符串未被识别为有效的datetime 类型
也是mm的原因 --------------------编程问答-------------------- 应该是 string borrowdate = (System.DateTime.Now).ToString("yyyy/MM/dd"); 吧 --------------------编程问答--------------------
string borrowdate = (System.DateTime.Now).ToString("yy-MM-dd");
改成这样就没有问题了 --------------------编程问答--------------------
补充:.NET技术 , ASP.NET