Subject Re: [ib-support] DATE Question
Author Ivan Prenosil
> Is there a setting somewhere to get the AM out of a date field?

Time is internally stored as Integer, so no AM/PM can be stored there.

> Year2 = cast(f_Year(:DateIN) as CHAR(4));
> Month2 = cast(F_Month(:datein) as VARCHAR(2));
> DayINT = F_DayOfMonth(:datein);

You do not need UDF. Use EXTRACT built in function instead.

> DateIn = F_StripTime(:DateIN);

You are probably using dialect-1 database, where DATE field
contains both date and time, right? In dialect-3 databases
DATE field contains date, TIME field contains time (of day),
and TIMESTAMP contains both date and time,
so there is no reason to strip time from DATE field.

> Or is
> there a better way of achieving converting a DATE field to a
> VARCHAR(8) column.

Either write UDF for formatting date, of try this:

CREATE PROCEDURE DATETOSTRING (
DATEIN TIMESTAMP)
RETURNS (
DATEOUT VARCHAR(8))
AS
DECLARE VARIABLE i INTEGER;
BEGIN
DATEOUT = EXTRACT (YEAR FROM DATEIN); /*we expect year to be 4 digits*/

i = EXTRACT (MONTH FROM DATEIN);
IF (i <=9) THEN DATEOUT = DATEOUT || '0';
DATEOUT = DATEOUT || i;

i = EXTRACT (DAY FROM DATEIN);
IF (i <=9) THEN DATEOUT = DATEOUT || '0';
DATEOUT = DATEOUT || i;

SUSPEND;
END


Ivan
http://www.volny.cz/iprenosil/interbase