日期加减,请高手帮忙,谢谢了(我是初学者)
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=borrowdate+00/00/30;
我想实现当前日期borrowdate加上30天,得到另一个日期shredate,但是老是出错
第二句应怎么改正?
另外插入数据库的当前日期不是2008/3/24,而是2008/9/24,相差六个月是怎么回事,检查了系统时间设置也没有错
请帮帮忙
--------------------编程问答-------------------- System.DateTime.Now.AddDays(30) --------------------编程问答--------------------
string borrowdate = (System.DateTime.Now).ToString("yy/mm/dd");--------------------编程问答-------------------- TimeSpan TS = new TimeSpan(30, 0, 0, 0);
string shredate=( System.DateTime.Now.AddDays(30)).ToString("yy/mm/dd");
DateTime dtime = Convert.ToDateTime(borrowdate);
shredate=dtime.Add(TS).ToString("yy/mm/dd"); --------------------编程问答-------------------- 用以上几种方法还不行
均提示:
该字符串未被识别为有效的datetime 类型
补充:.NET技术 , ASP.NET