Solved

ODBC Date Format

Posted on 2002-05-28
7
752 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now