temp="#" & cstr(a(0)) & "-" & cstr(a(1)) & "-" cstr(a(2)) & "#"
currdt=cdate(temp)
程序执行时提示temp不是有效的日期文字.将temp的值copy到cdate的参数中 去却能得到正确结果,为什么?temp的值最后是#9-29-4#
currdt=cdate(temp)
程序执行时提示temp不是有效的日期文字.将temp的值copy到cdate的参数中 去却能得到正确结果,为什么?temp的值最后是#9-29-4#
>currdt=cdate(temp)
>程序执行时提示temp不是有效的日期文字.将temp的值copy到cdate的参数中 去却能得到正确结果,为什么?>temp的值最后是#9-29-4# |
|
V
还是不正确Dim temp As String
Dim currdt As Date
temp = "2004-9-27"
currdt = CDate(temp)应该是你的输入的日期的格式有点问题。
cdate(#9-29-04#) 得到的结果才是2004-9-29我在立即窗口里试了的.
CURRDT = CDate(TEMP)
cdate()是date類型
currdt = CDate(TEMP)
currdt = CDate("#9-29-4#")
所以类型不对
而
currdt = CDate(#9-29-4#)
是对的
if isDate(temp) then
currdt=cdate(temp)
else
msgbox "不是日期格式"
end if日期最好这样来表示:yyyy-mm-dd ,如果使用日期文字(譬如#29/09/04#)这样有些函数不能识别
有效日期的范围介于公元 100 年 1 月 1 日与公元 9999 年 12 月 31 日之间
另外 使用cdata 前先用 isData 函数检查一下是不是日期
if isdate(temp) then
currdt = CDate(TEMP)
else
msgbox "wrong date format"
end if
>currdt=cdate(temp)
>程序执行时提示temp不是有效的日期文字.将temp的值copy到cdate的参数中 去却能得到正确结果,为什么?temp的值最后是#9-29-4#缺省格式是 US 格式:
temp="#" & cstr(a(0)) & "/" & cstr(a(1)) & "/" cstr(a(2)) & "#"
currdt = CDate("#9-29-4#")
所以类型不对
而
currdt = CDate(#9-29-4#)
是对的
我觉得他说的对,并不是分隔符的问题.