Solved

ODBC Date Format

Posted on 2002-05-28
7
765 Views
Last Modified: 2008-03-10
Hi, i usually use the ODBC date format, so my applications do not depend of the machine's regional configuration, like this:

{ ts '2002-02-02 00:00:00 ' }

This intends for { ts 'yyyy-mm-dd hh:mm:ss' }

This does work well when the query is armed inside an string variable and then thrown in the Execute method, but now i have to use parametrized queries, using the "?" sign and the Parameters collection. Too bad, i cannot make that the parameters collection accept the date values with the ODBC date format, i have to do it with the standard date format mm-dd-yyyy which does my application regional configuration dependent.

Is there a workaround for this???

Thanks
0
Comment
Question by:Cuervo
  • 4
  • 2
7 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7040643
Post your code and tell us what database your are using.

Anthony
0
 

Author Comment

by:Cuervo
ID: 7042631
SQL Server 7.0

Here is the code:


Private Sub collectParams(ByRef cmd As ADODB.Command, ByVal argparams As Variant)

Dim params As Variant, v As Variant
Dim iLength As Long
Dim i As Integer, l As Integer, u As Integer

If Not IsArray(argparams) Then Exit Sub
   
params = argparams
For i = LBound(params) To UBound(params)
    l = LBound(params(i))
    u = UBound(params(i))
    'Chequear por nulls
    If u - l = 3 Then
        If VarType(params(i)(3)) = vbString Then
            v = IIf(params(i)(3) = "", Null, params(i)(3))
        Else
            v = params(i)(3)
        End If
        'Chequear si el tamaño es 0
        If params(i)(2) <= 0 Then
            iLength = 1
        Else
            iLength = params(i)(2)
        End If
        cmd.Parameters.Append cmd.CreateParameter(params(i)(0), params(i)(1), adParamInput, iLength, v)
    Else
        RaiseError M_MODNAME, "collectParams(...): incorrect # of parameters", bWriteToLog:=True
    End If
Next i

End Sub

The code fails in the "cmd.Parameters.Append cmd.CreateParameter(params(i)(0), params(i)(1), adParamInput, iLength, v)" statement, because it doesn't accept the v value "{ ts '2002-01-01 00:03:00' }" with the params(i)(1)=adDBTimeStamp data type.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7042841
Just a quick response, before I look at it in more depth, the data type should be adDate not adDBTimeStamp

I realize this may have nothing to do with the subject, but are these parameters used in a Stored Procedure and if so can you post the Stored Procedure?

Anthony
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7043442
Also, please maintain this open question:

Hard disk drive knock out Date: 04/19/2002 10:55AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=hardgen&qid=20291520
Linux Proxy and Windows Client Date: 08/29/2001 09:55AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=linuxnet&qid=20175797

Thanks,
Anthony
0
 

Author Comment

by:Cuervo
ID: 7045576
Hi. Thanks for the answer. The store procedure is nothing really special, in fact, the code in here are not even feeling the store procedure. The value just doesn't get to it in this instances.

The store procedure that is using this function receives a paremeter that is a datetime.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 7045710
First of all I was wrong adDBTimeStamp is the correct type.

Second I should clarify that I do not use the ODBC driver (for performance reasons I use the SQL Server native driver).  However you may want to check out the following articles from MSDN:
FIX: Syntax Error When You Use ODBC Canonical Date Format as Parameter to SQL Stored Procedure (Q270586)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q270586&SD=MSKB&
FIX: Engine Does Not Handle Intl Dates in Localized Version (Q223318)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q223318&SD=MSKB&

Suerte,
Anthony
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7851216
Hi Cuervo,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept acperkins@devx's comment(s) as an answer.

Cuervo, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question