Type mismatch with FormatDateTime

Type mismatch with FormatDateTime

Post by Kayd » Sat, 12 Nov 2005 08:53:25


Hi:
I am passing a datetime from SQL Server and getting a "Type Mismatch"
error when I do in my ActiveX script task in my DTS package. Why a type
mismatch? Isn't a datetime value what is expected here?

Thanks,
Kayda

strSQL = "SELECT MAX([Timestamp]) AS MaxDate FROM " & TableName & "
WHERE Site = '" & SiteName & "'"
Set objRS1 = objconn.execute (strSQL)

If objRS1.EOF Then
varMaxDate = #1/1/1970#

Else
tempdate = objRS1.Fields("MaxDate")
varMaxDate = FormatDateTime(tempdate,2)
End If
 
 
 

Type mismatch with FormatDateTime

Post by Roland Hal » Sat, 12 Nov 2005 18:43:42


: Hi:
: I am passing a datetime from SQL Server and getting a "Type Mismatch"
: error when I do in my ActiveX script task in my DTS package. Why a type
: mismatch? Isn't a datetime value what is expected here?
:
: Thanks,
: Kayda
:
: strSQL = "SELECT MAX([Timestamp]) AS MaxDate FROM " & TableName & "
: WHERE Site = '" & SiteName & "'"
: Set objRS1 = objconn.execute (strSQL)
:
: If objRS1.EOF Then
: varMaxDate = #1/1/1970#
:
: Else
: tempdate = objRS1.Fields("MaxDate")
: varMaxDate = FormatDateTime(tempdate,2)
: End If

Where do you get the error? When the SQL statement is executed or when you
try to format the string to datetime?

If you get it during the format, then try changing this line from:

tempdate = objRS1.Fields("MaxDate")

to:

tempdate = CDate(objRS1.Fields("MaxDate"))

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.yqcomputer.com/
WSH 5.6 Documentation - http://www.yqcomputer.com/
MSDN Library - http://www.yqcomputer.com/