Solved

Date problem in Firebird

Posted on 2013-12-21
8
724 Views
Last Modified: 2013-12-26
Hi, I have a problem using dates in Firebird.
       T1:= StrToDate(MaskEdit3.Text);
       T2:= StrToDate(MaskEdit4.Text);

                  SQL.Text:= 'SELECT SUM(BEDRAGTOTAAL) AS SOM1 FROM KASSAVERKOPEN ' +
                             'WHERE ((FACTUURDATUM BETWEEN :pNu AND :pNi) ' +
                             'AND (KLANTID = :pKLANTID) AND (VOLDAAN = 1))';
                  ParamByName('pNu').AsDate:= T1;
                  ParamByName('pNi').AsDate:= T2;
                  ParamByName('pKLANTID').AsDate:= Temp1query1.FieldByName('KLANTID').AsInteger;;

Open in new window

I get an error when  (FACTUURDATUM BETWEEN :pNu AND :pNi) --> conversion error -303
"1899-12-31"

I tried tot use CAST, but the result is the same. What might be the problem here ?

thx
Mario
0
Comment
Question by:marioway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 19

Expert Comment

by:NickUpson
ID: 39734366
firebird doesn't like the format of the date string, is FACTUURDATUM a timestamp my any chance
0
 

Author Comment

by:marioway
ID: 39734554
No , Date

       with Distinctfactuurklantidquery do begin
        Close;
         SQL.Text:= 'SELECT DISTINCT KLANTID FROM FACTUUR ' +
                    'WHERE ((VOLDAAN = 1) AND (FACTUURDATUM BETWEEN BETWEEN :pNu AND :pNi))';
         ParamByName('pNu').AsDate:= T1;
         ParamByName('pNi').AsDate:= T2;
        Open;
        First;
       end;

this query for instance works fine; strange .....
0
 

Author Comment

by:marioway
ID: 39734559
Sorry, I see now that I made an error

ParamByName('pKLANTID').AsDate:= Temp1query1.FieldByName('KLANTID').AsInteger;

Should be:   ParamByName('pKLANTID').AsInteger:= Temp1query1.FieldByName('KLANTID').AsInteger;;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:NickUpson
ID: 39734571
if you replace the variables with hard-coded values does it work then, try several different formats and dates and post the results
0
 

Author Comment

by:marioway
ID: 39734581
Nick, it works now, I coded: ParamByName('pKLANTID').AsDate, should be: ASINTEGER

Mario
0
 
LVL 19

Assisted Solution

by:NickUpson
NickUpson earned 250 total points
ID: 39734626
so basically wrong error message

btw: seems wierd you are selecting based on primary key (I assume pklandid) and other criteria at the same time
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 250 total points
ID: 39735568
So, this is solved. But just for info about formatting in firebird:
http://mc-computing.com/Databases/delphi/Firebird/Dates.html
Although we can use:
ParamByName('....').AsDate ...
I prefer to use "native" string formatting in code and concatenate into sql string.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

710 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