注册 登录
编程论坛 ASP.NET技术论坛

[求助]sql server中插入时间的格式

tm_ma 发布于 2007-10-01 11:53, 1484 次点击
很简单的一个问题,理由是以前我都是用access,哈哈,下面这句话中插入时间怎么写?
————————————————————————————————————————
Dim strSql As String = "insert into mood(theme,[content],submit_date) values('hello','how are you',2007-9-29)"
如果我是想取得当前的时间,我要怎么写?
7 回复
#2
重在参与2007-10-01 20:29
string strTime=DateTime.Now.ToString("yyyy-MM-dd");
insert into mood(submit_date) values(strTime)
#3
purana2007-10-01 20:36
"insert into mood(theme,[content],submit_date) values('hello','how are you',getdate())"
#4
skyland842007-10-02 10:40

Dim strSql As String = "insert into mood(theme,[content],submit_date) values('hello','how are you',2007-9-29)"
如果我是想取得当前的时间,我要怎么写?

改成这样 把日期转成字符串 插入就可以乐!

Dim strSql As String = "insert into mood(theme,[content],submit_date) values('hello','how are you',‘2007-9-29’)"
如果我是想取得当前的时间,我要怎么写?

#5
purana2007-10-02 10:48
以下是引用purana在2007-10-1 20:36:46的发言:
取得当前时间
"insert into mood(theme,[content],submit_date) values('hello','how are you',getdate())"

#6
purana2007-10-02 10:48
4楼的单引号是错误的.
#7
梦灵儿2007-10-02 12:02
string date=(DataTime.Now).tostring();
直接把这个变量插入进去
#8
tm_ma2007-10-02 12:47
明白
1