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

时间格式的统一

zmhdxy 发布于 2007-11-05 17:20, 523 次点击
<%
Function AddZero(val, digit)
Dim Ret
Ret = CStr(val)
Ret = Replace(Space(digit - Len(val)), " ", "0") & Ret
AddZero = ret
End Function
Function MFormatDataTime(dt, format)
Dim ret
ret = Replace(format, "MM", Month(dt))
ret = Replace(ret, "M",AddZero(Month(dt), 2))
ret = Replace(ret, "mm",Minute(dt) )
ret = Replace(ret, "m", AddZero(Minute(dt), 2))
ret = UCase(ret)
ret = Replace(ret, "YYYY", Year(dt))
ret = Replace(ret, "DD", Day(dt))
ret = Replace(ret, "D", AddZero(Day(dt), 2))
ret = Replace(ret, "HH", Hour(dt))
ret = Replace(ret, "H", AddZero(Hour(dt), 2))
ret = Replace(ret, "SS", Second(dt))
ret = Replace(ret, "S", AddZero(Second(dt), 2))
MFormatDataTime = ret
End Function

sql语言

StrSql="insert into Diary(Title,Reply,user_name,content,submit_date) values('" & tx1 & "','主题','版主','" & tx2 & "',#" & MFormatDataTime(Now(), "yyyy-MM-dd hh:mm:ss") & "#)"


上面的代码是有错的 请高手帮忙
3 回复
#2
zmhdxy2007-11-11 18:28

怎么没人回答啊 我自己搞顶了 把数据库文件里的时间格式改成文本就行了

#3
永夜的极光2007-11-11 18:48
你这个字段是用来保存加入记录的时间,

如果数据库是access就不需要这么麻烦,

只要在设计数据库的时候,这个字段的默认值设为“Now()”

添加的时候不要添加这个字段

这样就可以了
#4
lq73506842007-11-12 11:13
sql数据库其实也可以
在设计数据库的时候,这个字段的默认值设为date()
添加的时候不要添加这个字段
1