Search code examples
vb6

How to un trim the date in vb6 (milliseconds must appear). The date is coming from stored procedure in sybase


I have a problem of passing a full datetime value from VB6 to sybase using ADO. It seems the milliseconds are left out.

Here's example code for the stored procedure:

CREATE PROCEDURE dbo.usp_ReturnDatetimeInput (
  @Input datetime, 
  @Output datetime output
)
AS
--Show input value
print '@Input = ' + convert(varchar(20), @Input, 14)
set @Output = @Input
GO

vb6 code

Private Function TestDatetimeOutputValue(dInput as Date) As Date
  Dim cmd As New ADODB.Command
  With cmd
  <snip>
  .Parameters.Append .CreateParameter("@Input", adDBTimeStamp, , 8, dInput)
  .Parameters.Append .CreateParameter("@Output", adDBTimeStamp, adParamOutput, 8, dInput)
  .Execute

  If Not IsEmpty(.Parameters("@Output").Value) Then
    TestDatetimeOutputValue = .Parameters("@Output").Value
  End If
  End With
End Function

Solution

  • An adDBTimeStamp field is not a VB Date type. By blithely assigning its value to a Date variable you have converted it, truncating it to fit.

    See How To Get Fractions of a Second from ADO adDBTimeStamp Field. archive

    You can choose how to carry such values to work with them in VB6. One option might be a UDT with a Date field and a Long or Integer to hold the milliseconds. Another might be to calculate something you store in a Decimal or Currency type variable, where you scale the Date value up to a whole part and add in the ms. as a fractional part for example.