Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 6th, 2004, 05:55 AM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
How to insert a date?

I notice that firebird expects the date-format to be MM-DD-YYYY for an insert.
So the following statement will be correct:
insert into my table values ('08-31-2004');

However I want to insert a date with the format 'DD-MM-YYYY' (that's the format my application sends the field to firebird). But when I do:
insert into my table values ('31-08-2004');
I get the error "Overflow occurred during data type conversion". (Which seems logical because 31 is not a valid month).

Is it somehow possible to insert a date with the format DD-MM-YYYY and if yes how?

Thanks in advance, Peter

Reply With Quote
  #2  
Old September 6th, 2004, 07:02 AM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
In addition to this:
Sometimes the date column can be empty, but I still have to do an insert. When I do something like this, I get an error again (unknown token).
insert into table(id,name,date) values (1,'test','');

It works correctly when I do:
insert into table(id,name,date) values (1,'test',null);

However: my stored procedure, which handles the insert-statement, gets an empty string as input variable. How to convert this '' to null in a stored procedure.

Thanks again! Peter

Reply With Quote
  #3  
Old September 7th, 2004, 10:56 PM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Anyone?
Come one guys; this question cannot be to difficult!
Any help is appreciated!!

Reply With Quote
  #4  
Old September 8th, 2004, 01:38 AM
upscene upscene is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 223 upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level)upscene User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 14 m 50 sec
Reputation Power: 8
Hi,

If your procedure accepts a DATE as the value, it won't allow '' to get accepted. If you're accepting a VARCHAR as the parameter, you could easily check:

CREATE PROCEDURE <name> (..., ..., dateinput varchar(10) )
...
DECLARE VARIABLE mydate DATE;
...
AS
BEGIN
if (dateinput = '')
then mydate = NULL;
else mydate = cast(dateinput as DATE);
INSERT INTO mytable (...) VALUES (..., :mydate);
END

As for the DD-MM-YYYY thing: Firebird accepts several formats, but by using / or - it accepts the MM-DD-YYYY format. I believe you can do DD.MM.YYYY.

The best thing would be to accept a DATE only and on the client side pass a date instead of a string.


With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL Server.
Upscene Productions
http://www.upscene.com
__________________
Martijn Tonies
Database Workbench: developer IDE for Firebird, MySQL, InterBase, MSSQL Server and Oracle
Upscene Productions
http://www.upscene.com

Reply With Quote
  #5  
Old September 8th, 2004, 03:12 AM
pmanten pmanten is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 51 pmanten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanks a lot Martijn!!

I didn't know you could use 'cast' in a stored procedure. In fact, I didn't know cast existed at all in firebird.
I read the standard documentation about stored procedures and triggers and it isn't described there. Or maybe I'm not looking at the right place. Can you recommend some documentation where this is described?

I'm using a varchar input variable, because I receive the date fromm an html-form and I want to send this directly to Firebird (after checking on the client side with javascript if it's valid date). My php serverside script is just getting it from html as a string and immediately sending it to Firebird as a string. It might be better though to first change it in a date, before passing it... (or change the dd-mm-yyyy string to mm-dd-yyyy)

Thanks again!
Peter

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > How to insert a date?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT