sep*_*ith 0 vbscript asp-classic
我是一个运行VB脚本与asp经典,我收到以下错误:
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'FormatDateTime'
/whatsnew/updated_pages_www.htm, line 52
Run Code Online (Sandbox Code Playgroud)
我试图找出导致错误的原因.csv文件中的日期格式有什么问题吗?日期格式为:20090220122443
以下页面代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.CharSet = "UTF-8" %>
<%
pagetitle="What was published last week on casa.gov.au"
%>
<%
connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("/whatsnew/data")
set connect = Server.CreateObject("ADODB.connection")
connect.open connectString
selectSQL = "SELECT * FROM www.csv"
set www_RS = connect.execute(selectSQL)
%>
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<p class="breadCrm"><a href="/index.htm">Home</a> <span>></span> <a href="/whatsnew/index.htm">What's New</a></p>
<!--<img src="/_lib/images/menu/yourarea.gif" alt="" width="891" /> -->
<div class="twoColumnRow">
<div class="twoColumnContent">
<div class="contentPad">
<!-- Start of main content -->
<p class="imageRight"> </p>
<h1><%=pagetitle%></h1>
<%
www_RS.MoveFirst
%>
<caption><h3>New or Amended on www.casa.gov.au</h3></caption>
<ul class="relatedInfoLinks">
<%
Dim pagecode, pagecode2, newfiledate, publisheddate, moddate, createddate, newfilediff, recently_published
pagecode = www_RS("PAGECODE").Value
While not www_RS.EOF
pagecode = www_RS("PAGECODE").Value
pagecode2 = Instr(pagecode,"PC_")
pagecode3 = Instr(pagecode,"~")
createddate = FormatDateTime(www_RS("CREATED_DATE").Value,1)
moddate = FormatDateTime(www_RS("MOD_DATE").Value,1)
publisheddate = FormatDateTime(www_RS("PUB_DATE").Value,1)
newfilediff = DateDiff("y",www_RS("CREATED_DATE").Value,www_RS("PUB_DATE").Value)
recently_published = DateDiff("y",www_RS("PUB_DATE").Value,dtNow)
if (pagecode2 = 1) and (pagecode3 = 0) and (recently_published < 8) then
%>
<li>
<%
Response.Write("<a href='http://casa.gov.au/scripts/nc.dll?WCMS:STANDARD::pc=" & pagecode & "'>" & www_RS("DESCRIPTION").Value & "</a>")
%>
<BR>
Last modified <%=publisheddate%>
<BR>
<%
if newfilediff < 8 then
%>
<span style="color:red">* This is a new page</span>
<%
end if
%>
</li>
<BR>
<%
end if
www_RS.MoveNext
Wend
%>
</ul>
<!-- End of main content -->
</div> <!-- end contentPad div -->
</div> <!-- end twocolumncontent div -->
<div class="twoColumnLinks">
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"-->
</div> <!-- end twocolumnlinks div -->
</div> <!-- end twocolumnrow div -->
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"-->
Run Code Online (Sandbox Code Playgroud)
该FormatDateTime函数需要有效格式化的日期作为第一个参数.
根据您所在位置使用的日期/时间格式,它将是这样的(例如:美国日期格式):
"02-20-2009 11:24:43 AM"
"02/20/2009 11:24:43 AM"
"02-20-2009 14:24:43"
"02/20/2009 14:24:43"
Run Code Online (Sandbox Code Playgroud)
作为测试,您可以检查这样的日期的有效性:
d = CDate("02-20-2009 11:24:43 AM")
d = CDate("02/20/2009 11:24:43 AM")
d = CDate("02-20-2009 14:24:43")
d = CDate("02/20/2009 14:24:43")
Run Code Online (Sandbox Code Playgroud)
或者,使用IsDate:
b = IsDate("02-20-2009 11:24:43 AM")
b = IsDate("02/20/2009 11:24:43 AM")
b = IsDate("02-20-2009 14:24:43")
b = IsDate("02/20/2009 14:24:43")
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您的日期字符串:"20090220122443"是有效的日期/时间,但它不是有效的日期/时间格式.
您可以使用函数将日期字符串转换为有效格式.以下是一些进行转换的代码示例.
strDate = "20090220122443"
wscript.echo "strConvertDateString(strDate) =" & strConvertDateString(strDate)
wscript.echo "dateConvertDateString(strDate)=" & dateConvertDateString(strDate)
wscript.echo
wscript.echo FormatDateTime(strConvertDateString(strDate),1)
wscript.echo FormatDateTime(dateConvertDateString(strDate),1)
wscript.echo
Function strConvertDateString (strDateString)
strConvertDateString = mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2)
End Function
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
Run Code Online (Sandbox Code Playgroud)
该函数strConvertDateString接受格式的日期/时间字符串,并以函数可接受的格式返回字符串FormatDateTime.
该函数dateConvertDateString接受格式的日期/时间字符串并返回日期(CDate),该FormatDateTime函数也可以接受.
第一个应该在大多数地方工作.如果特定于您的位置的日期转换存在问题,则第二个可能会更好.您应该只需要实现和使用这两个函数之一.
在任何情况下,根据您的位置,您可能需要编辑功能以调整mid()用于撰写日期/时间字符串的方式.
注意:这是为了在VBScript(cscript.exe)中进行测试而编写的.将函数复制/剪切/粘贴到您的.asp文件中以供使用.然后使用这样的函数:
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
Run Code Online (Sandbox Code Playgroud)
编辑:
以下是如何将此功能添加到.asp页面以及如何使用该功能的更详细说明.
首先,您需要将该功能添加到您的ASP页面.
编辑您的页面.
通常,函数声明放在<head>部分内部,如下所示:
<html>
<head>
...
...
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
</head>
<body>
...
<!-- there will be more <html> or <% asp code %> here ... -->
Run Code Online (Sandbox Code Playgroud)
或者,在这样的<body>部分内:
<html>
<head>
...
...
</head>
<body>
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
...
<!-- there will be more <html> or <% asp code %> here ... -->
Run Code Online (Sandbox Code Playgroud)
在你的情况下,它看起来像包含页面的部分<html>,<head>,</head>,和<body>标签可以被包含在包含的文件.您可以通过检查文件来验证:
"/_lib/include/header.htm"
"/_lib/include/menu.htm"
Run Code Online (Sandbox Code Playgroud)
因此,在您的情况下,您需要在行之后将函数声明插入到页面中<!--#INCLUDE VIRTUAL=,例如:
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
Run Code Online (Sandbox Code Playgroud)
或者,您可以将函数声明插入其中一个文件中:
"/_lib/include/header.htm"
"/_lib/include/menu.htm"
Run Code Online (Sandbox Code Playgroud)
接下来,找到使用VBScript日期函数的语句,其中您当前传递的日期格式如下: "20090220122443"
那将是(最有可能)所有这些:
createddate = FormatDateTime(www_RS("CREATED_DATE").Value,1)
moddate = FormatDateTime(www_RS("MOD_DATE").Value,1)
publisheddate = FormatDateTime(www_RS("PUB_DATE").Value,1)
newfilediff = DateDiff("y",www_RS("CREATED_DATE").Value,www_RS("PUB_DATE").Value)
recently_published = DateDiff("y",www_RS("PUB_DATE").Value,dtNow)
Run Code Online (Sandbox Code Playgroud)
并编辑这些语句以使用该函数转换日期,如下所示:
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
moddate = FormatDateTime(dateConvertDateString(www_RS("MOD_DATE").Value),1)
publisheddate = FormatDateTime(dateConvertDateString(www_RS("PUB_DATE").Value),1)
newfilediff = DateDiff("y",dateConvertDateString(www_RS("CREATED_DATE").Value),dateConvertDateString(www_RS("PUB_DATE").Value))
recently_published = DateDiff("y",dateConvertDateString(www_RS("PUB_DATE").Value),dtNow)
Run Code Online (Sandbox Code Playgroud)
因此,如果您在问题中提供的代码仍然正确且完整,则使用日期转换功能的代码相同:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.CharSet = "UTF-8" %>
<%
pagetitle="What was published last week on casa.gov.au"
%>
<%
connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("/whatsnew/data")
set connect = Server.CreateObject("ADODB.connection")
connect.open connectString
selectSQL = "SELECT * FROM www.csv"
set www_RS = connect.execute(selectSQL)
%>
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
<p class="breadCrm"><a href="/index.htm">Home</a> <span>></span> <a href="/whatsnew/index.htm">What's New</a></p>
<!--<img src="/_lib/images/menu/yourarea.gif" alt="" width="891" /> -->
<div class="twoColumnRow">
<div class="twoColumnContent">
<div class="contentPad">
<!-- Start of main content -->
<p class="imageRight"> </p>
<h1><%=pagetitle%></h1>
<%
www_RS.MoveFirst
%>
<caption><h3>New or Amended on www.casa.gov.au</h3></caption>
<ul class="relatedInfoLinks">
<%
Dim pagecode, pagecode2, newfiledate, publisheddate, moddate, createddate, newfilediff, recently_published
pagecode = www_RS("PAGECODE").Value
While not www_RS.EOF
pagecode = www_RS("PAGECODE").Value
pagecode2 = Instr(pagecode,"PC_")
pagecode3 = Instr(pagecode,"~")
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
moddate = FormatDateTime(dateConvertDateString(www_RS("MOD_DATE").Value),1)
publisheddate = FormatDateTime(dateConvertDateString(www_RS("PUB_DATE").Value),1)
newfilediff = DateDiff("y",dateConvertDateString(www_RS("CREATED_DATE").Value),dateConvertDateString(www_RS("PUB_DATE").Value))
recently_published = DateDiff("y",dateConvertDateString(www_RS("PUB_DATE").Value),dtNow)
if (pagecode2 = 1) and (pagecode3 = 0) and (recently_published < 8) then
%>
<li>
<%
Response.Write("<a href='http://casa.gov.au/scripts/nc.dll?WCMS:STANDARD::pc=" & pagecode & "'>" & www_RS("DESCRIPTION").Value & "</a>")
%>
<BR>
Last modified <%=publisheddate%>
<BR>
<%
if newfilediff < 8 then
%>
<span style="color:red">* This is a new page</span>
<%
end if
%>
</li>
<BR>
<%
end if
www_RS.MoveNext
Wend
%>
</ul>
<!-- End of main content -->
</div> <!-- end contentPad div -->
</div> <!-- end twocolumncontent div -->
<div class="twoColumnLinks">
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"-->
</div> <!-- end twocolumnlinks div -->
</div> <!-- end twocolumnrow div -->
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"-->
Run Code Online (Sandbox Code Playgroud)
要试一试,请将当前.htm文件复制到类似的地方whatever.htm.然后,用.htm上面的代码替换(或编辑)您的电流.
不幸的是,我没有办法测试你的整个ASP页面.
如果您仍然遇到此问题,如果您可以提供实际.htm文件的副本以及文件的副本,那将非常有用:/_lib/include/header.htm和/_lib/include/menu.htm