Morning NickUpson
Is there now way where I can format the Date variable in a select like with Sql server.
select convert(char(15),getdate()
Thanx
Main Topics
Browse All TopicsGood day,
I need to do a select statement where I can format a Date Field to a string field in the format of yyyy/mm/dd.
I have created a work table where I insert values into, my work table have a Field called ExDate declared as char(10).
I do a insert into this table from a table where I have a Field Called ArrDate declared as Date variable, I need to convert this ArrDate to a string but in the following format yyyy/mm/dd.
The reason why I need the fields as a string is, because this field is updated to null sometimes if it met a certion condition, If I use a Date variable and update it to null then I get a value of 1899/01/01 I dont want that.
I have tried the following but dont know how the get a leading zero in front of the month and day if the day or month is less then ten.
select EXTRACT(YEAR FROM ArrDate)||'/' || EXTRACT(MONTH FROM ArrDate)||'/' || EXTRACT(DAY FROM ArrDate) from Par
Please show how I can format this select statement.
thanx
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
no, not when you want the leading zeros. firebird & interbase don't have such non-standard sql capabilities. To put the leading zero in place you need 'if'
you can do
select cast(arrdate as char(25)) from Par
but that may not give the correct format either (but does seem to give the leading zero, with enough substring calls it should be possible)
Hi NickUpson
I am very confused, I hope you can answer me on the following.
If for example I have a table Test declared as Follows :
create table Test (ArrDate Date, RValue numeric(9,2))
insert into Test (ArrDate,RValue) VALUES (null,99.99)
if I select now from Test I get the following
null,99.99
Previously I said I got 1899/01/01, I need to know from you if I put a null value any type field , will I always get a null return,
where do you think I got the 1899/01/01 value from.
Will the null make the field as empty like '' ???
Sorry I hope you understand what I am trying to say now, but If the null will return a empty value , then my problem is 100% solved.
The reason why I want sometimes a null is because some of the data I must return must not have a date value in, but other data must have a date value in.
I want in my procedure to update some records and set ArrDate = null when it met a certain condition, and then it must not show anything in delphi if it is a null.
Here is a example of my report in delphi.
Client Status Arrivial Date
A Active 01/01/2007
B NOT
C NOT
D ACTIVE 01/01/2007
E ACTIVE 01/01/2007
this is how the data must look, but it seems the null update work now.
thanx
henry
> I need to know from you if I put a null value any type field , will I always get a null return
yes
> where do you think I got the 1899/01/01 value from.
cast(0 as date) might do that
make sure you are VERY clear on empty string is the same as '' is NOT the same as NULL, (although you can choose to display NULL as '' if you wish by using coalesce(fieldname, '')
Business Accounts
Answer for Membership
by: NickUpsonPosted on 2007-01-07 at 09:54:37ID: 18262478
If a field has null in it I would expect null back, so your easiest thing would be to fix that
the way to deal with your format issue above is to use a stored procedure, something like
create or ALTER PROCEDURE my_proc(DATE_IN TIMESTAMP)
RETURNS (RES_STR CHAR(10))
AS
declare variable num1 Integer;
declare variable num2 Integer;
declare variable num3 Integer;
begin
num1 = EXTRACT(year FROM :DATE_IN);
num2 = EXTRACT(month FROM :DATE_IN);
num3 = EXTRACT(day FROM :DATE_IN);
if (num2 > 9) then
res_str = cast(num1 as char(2)) || '/' || cast(num2 as char(2)) ;
else
res_str = cast(num1 as char(2)) || '/0' || cast(num2 as char(1));
if (num3 > 9) then
res_str = res_str || '/' || cast(num3 as char(2)) ;
else
res_str = res_str || '/0' || cast(num3 as char(1));
suspend;
end
^
and call it as select * from my_proc(ArrDate);