EscapeDate Function:
Escapes a variant date for sql server.
Description:
EscapeDate Function escapes a date for sql server statements. If the input is not recognized as a date, EscapeDate will return "null" otherwise it will return the date in between apostrophes such as '1/1/2001'.
Syntax:
escapedString = EscapeDate(variantDate)
Example:
<%
dim dDate, sql
dDate = now
sql = "select * from table where date_field between '1/1/01' and " & escapedate(dDate)
%>
ASP Source Code:
<%
function escapedate(byval sInput) if isnull(sInput) then escapedate = "null" exit function end if if len(trim(sInput)) = 0 then escapedate = "null" exit function end if if not isdate(sInput) then escapedate = "null" exit function end if escapedate = "'" & replace(formatdatetime(sInput, 2), "'", "''") & "'" end function
%>
|