Re: HELP: Explicit conversion in ODS
Posted in 1997
On Wed, 29 Oct 1997, Kyle Campbell wrote:
> My DBDATE environment variable is set to "Y2MD0" for application
> compatibility reasons. In one case I'd like to convert the date to
> format "MD2Y/". Is there a way to explicitly convert between types?
There is some confusion here. At the least, I'm a bit confused about how
to explain what's going on, but I'm going to try... You also haven't given
us very much information to go on about what programming language you're
using to access the data, which complicates matters.
First of all, DBDATE only affects the conversion of dates between strings
and DATE values; internally, the storage representation of a date is the
same regardless of the value of DBDATE. So, inside the database, there is
no distinction between 971030 and 1997-10-30 and 10/30/1997 and 30/10/1997;
they all have the same value.
So, the question becomes: where do you want to show the date in the MDY2/
format? If it is in the application program, then you use the relevant
conversion functions - rfmtdate() in ESQL/C or C or C++, and USING in I4GL
or NewEra. If you want to do it in DB-Access or inside the engine, then
you are going to have to work harder, probably using a stored procedure:
-- Untested code!
create procedure to_mdy2(d date) returning char(8); define dd, mm, yy integer;
define s char(8);
let dd = DAY(d);
let mm = MONTH(d);
let yy = YEAR(d) - 1900;
let s = mm || '/' || dd || '/' || yy;
return s;
end procedure;
Finally, note that the year 2000 is just around the corner and using
2-digits for the year is error prone. DON'T DO IT, please!
> Also, could I assign an int to a character string and have the leftmost
> blank characters be "buffered" with 0's?
Which language? In NewEra/I4GL, you can use:
LET str = intval USING "-&&&&&&&&&&"
Other languages require alternative techniques.
Yours,
Jonathan Leffler (johnl@informix.com) #include <witticism.h>