Chức năng: Chuyển đổi biến ngày tháng cho sql server
Ngôn ngữ: asp - Nhóm: database
CÚ PHÁP
escapedString = EscapeDate(variantDate)
Chuyển đổi thành giá trị ngày tháng chuẩn dùng trong SQL server. Nếu giá trị input không hợp chuẩn, giá trị null được trả về hoặc trả về giá trị giữa dấu nháy '1/1/2001'.
VÍ DỤ
<%
dim dDate, sql
dDate = now
sql = "select * from table where date_field between '1/1/01' and " & escapedate(dDate)
%>
ASP 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
%>