asp classic - Error with FormatDateTime in VBscript -
i running vb script asp classic , getting following error:
microsoft vbscript runtime error '800a0005' invalid procedure call or argument: 'formatdatetime' /whatsnew/updated_pages_www.htm, line 52
i trying work out causing error. there wrong format of date in csv file? date format is: 20090220122443
page code below:
<%@language="vbscript" codepage="65001"%> <% response.charset = "utf-8" %> <% pagetitle="what 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 * 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) , (pagecode3 = 0) , (recently_published < 8) %> <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 %> <span style="color:red">* 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"-->
the formatdatetime
function requires validly formatted date first parameter.
depending on date/time format used in location, (example: date format):
"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"
as test, can check validity of date this:
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")
or, using 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")
in case, date string: "20090220122443"
valid date/time, not in valid date/time format.
you use function convert date string valid format. here example of code conversion.
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
the function strconvertdatestring
accepts date/time string in format , returns string in format acceptable formatdatetime
function.
the function dateconvertdatestring
accepts date/time string in format , returns date (cdate), acceptable formatdatetime
function.
the first 1 should work in locations. second might work better if there issues date conversions particular location. should need implement , use 1 of these 2 functions.
in case, depending on location, may need edit functions adjust way mid()
used compose date/time string.
note: written testing in vbscript (cscript.exe). copy/cut/paste function .asp
file use. use function this:
createddate = formatdatetime(dateconvertdatestring(www_rs("created_date").value),1)
edit:
here more detailed explaination of how add function .asp
page , how use function.
first, need add function asp
page.
edit page.
normally, function declarations placed inside <head>
section this:
<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 more <html> or <% asp code %> here ... -->
or, inside <body>
section this:
<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 more <html> or <% asp code %> here ... -->
in case, looks sections of page contain <html>
, <head>
, </head>
, , <body>
tags contained in included files. can verify examining files:
"/_lib/include/header.htm" "/_lib/include/menu.htm"
so, in case, you'll want insert function declaration page after <!--#include virtual=
lines, like:
<!--#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 %>
or, insert function declaration one of these files:
"/_lib/include/header.htm" "/_lib/include/menu.htm"
next, find statements using vbscript date functions passing dates formatted this: "20090220122443"
that (most likely) of these:
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)
and edit statements use function convert dates, this:
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)
so, if code provided in question still correct , complete, here same code using date conversion function:
<%@language="vbscript" codepage="65001"%> <% response.charset = "utf-8" %> <% pagetitle="what 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 * 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) , (pagecode3 = 0) , (recently_published < 8) %> <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 %> <span style="color:red">* 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"-->
to give try, copy current .htm
file whatever.htm
. then, replace (or edit) current .htm
code above.
unfortunately, don't have way test complete asp
page.
if still have problems this, helpful if provide copy of actual .htm
file, , copy of files: /_lib/include/header.htm
, , /_lib/include/menu.htm
Comments
Post a Comment