SQL_Date Function:
Prepare dates for SQL query.
Description:
SQL_Date Function prepares dates for SQL query. It needs the DateDB Function. Database type: MSAccess, MSSQL, MySQL, Oracle
Syntax:
formatteddate = SQL_Date("datevalue", "databasetype")
Details:
Arguments:
datevalue: any date value e.g. 27/10/2006
databasetype: MSAccess MSSQL MySQL Oracle
Example:
<%
Dim a a = SQL_Date("27/10/2006", "MSAccess") '--- returns: #2006-10-27#
a = SQL_Date("27/10/2006", "MSSQL") '--- returns: CONVERT(DATETIME, '20061027', 112)
a = SQL_Date("27/10/2006", "MySQL") '--- returns: '2006-10-27'
a = SQL_Date("27/10/2006", "Oracle") '--- returns: TO_DATE('2006-10-27', 'YYYY-MM-DD') or '--- returns: TO_DATE('2006-10-27 22:12:05', 'YYYY-MM-DD HH24:MI:SS')
%>
ASP Source Code:
<%
Public Function SQL_date(ByRef adExpression, ByRef DbType) '--- If Expression valid date If IsDate(adExpression) Then '--- Return Date If LCase(DbType) = "access" Then SQL_date = "#" & adExpression & "#" '--- Access Database Elseif LCase(DbType) = "mssql" Then SQL_date = "CONVERT(DATETIME, '" & Replace(DataDB(adExpression), "-", "") & "', 112)" '--- MSSQL Database Elseif LCase(DbType) = "oracle" Then If datepart("h", DataDB(adExpression)) <> 0 OR datepart("n", DataDB(adExpression)) <> 0 OR datepart("s", DataDB(adExpression)) <> 0 Then SQL_date = "TO_DATE('" & DataDB(adExpression) & "', 'YYYY-MM-DD HH24:MI:SS')" '--- Oracle Database Else SQL_date = "TO_DATE('" & DataDB(adExpression) & "', 'YYYY-MM-DD')" '--- Oracle Database End if Else SQL_date = "'" & adExpression & "'" ' SQL Database End if '--- Else Expression not valid date Else '--- Return NULL SQL_date = "NULL" End If '--- IsDate(adExpression) End Function '--- SQL_date
%>
|