时间格式问题
date字段 类型是datetime
我想把存入的时间存成2007-01-01 00:00:00
date要怎么写入数据
我用date=now()不行啊
------解决方案-------------------- <%
set rs=server.createobject( "adodb.recordset ")
sql= "select * from news "
rs.open sql,conn,1
Mtime=rs( "dateandtime ")
Function FormatDate(ByVal sValue)
Dim Temp
If IsDate(sValue) Then
Temp = Year(sValue) & "- " & Right( "0 " & Month(sValue), 2) & "- " & Right( "0 " & Day(sValue), 2)
Else
Temp = "0000-00-00 "
End If
FormatDate = Temp
End Function
Function mDate()
mDate = FormatDate(Mtime)
End Function
Response.Write(mDate())
%>
这个我前几天刚在csdn看到有人写过的一个函数,我把他用在数据库中了,你看看!!
------解决方案-------------------- 'dtos函数就是让一位数变成两位数的,num为数值型参数,参数返回值为字符串型
function dtos(num)
dtos=cstr(num)
if len(dtos) <2 then
for i=1 to 2-len(dtos)
dtos= "0 "&dtos
next
else
dtos=dtos
end if
datetime_a=cstr(year(now))& "- "&dtos(month(now))& "- "&dtos(day(now))& " "&dtos(hour(now))& ": "&dtos(minute(now))& ": "&dtos(second(now))
再就是把数据库内该字段改为字符串型,不能为时间日期型格式,然后再
rs( "date ")=datetime_a
上面函数临时写的,还没有测试,你试试先
------解决方案--------------------function dtos(num)
dtos=cstr(num)
if len(dtos) <2 then
for i=1 to 2-len(dtos)
dtos= "0 "&dtos
next
else
dtos=dtos
end if
datetime_a=cstr(year(now))& "- "&dtos(month(now))& "- "&dtos(day(now))& " "&dtos(hour(now))& ": "&dtos(minute(now))& ": "&dtos(second(now))
end function
再就是把数据库内该字段改为字符串型,不能为时间日期型格式,然后再
rs( "date ")=datetime_a
同意思楼上的
------解决方案--------------------rs( "date ")=changedatetime(now())
function changedatetime(filename)
filename=replace(replace(replace(filename, "- ", "| "), " ", "| "), ": ", "| ")
filename=split(filename, "| ")
changedatetime=admin_datetime(filename(0))& "/ "&admin_datetime(filename(1))& "/ "&admin_datetime(filename(2))& "/ "&admin_datetime(filename(0))&admin_datetime(filename(1))&admin_datetime(filename(2))&admin_datetime(filename(3))&admin_datetime(filename(4))&admin_datetime(filename(5))
end function
function admin_datetime(datetime)
if len(datetime)> 1 then
admin_datetime=datetime
else
admin_datetime= "0 "&datetime
end if
end function