Subject | Re: [firebird-support] Re: How to pass a TIMESTAMP value to a Pascal UDF |
---|---|
Author | Hans |
Post date | 2009-11-28T19:12:54Z |
With a little bit of playing around, how would this fit ?
CREATE PROCEDURE MI_FECHA( DATETIME TIMESTAMP )
RETURNS ( FECHA VARCHAR( 60 ) )
AS
DECLARE VARIABLE MES VARCHAR (60) =
'-ENE--FEB--MAR--ABR--MAY--JUN--JUL--AGO--SEP--OCT--NOV--DIC-';
DECLARE VARIABLE DAYS_STR VARCHAR(4);
DECLARE VARIABLE HOURS_STR VARCHAR(4);
DECLARE VARIABLE MINS_STR VARCHAR(4);
DECLARE VARIABLE AM_PM_STR VARCHAR(4);
BEGIN
IF (COALESCE(DATETIME,NULL) = NULL) THEN
FECHA = 'Fetcha Invalido';
ELSE
BEGIN
DAYS_STR = EXTRACT (DAY FROM DATETIME);
IF (DAYS_STR < 10) THEN
DAYS_STR = '0' || DAYS_STR;
FECHA = DAYS_STR;
FECHA = FECHA || SUBSTRING(MES FROM (EXTRACT (MONTH FROM DATETIME)-1)*5+1
FOR 5);
FECHA = FECHA || CAST(EXTRACT (YEAR FROM DATETIME) AS CHAR(4)) || ' ';
HOURS_STR = EXTRACT (HOUR FROM DATETIME);
IF (HOURS_STR < 12) THEN
AM_PM_STR = ' am';
ELSE
BEGIN
HOURS_STR = CAST(HOURS_STR AS INTEGER) - 12;
AM_PM_STR = ' pm';
END
IF (HOURS_STR < 10) THEN
HOURS_STR = '0' || HOURS_STR;
MINS_STR = EXTRACT (MINUTE FROM DATETIME);
IF (MINS_STR < 10) THEN
MINS_STR = '0' || MINS_STR;
FECHA = FECHA || HOURS_STR || ':' || MINS_STR || AM_PM_STR;
END
SUSPEND;
END
and then the select simply becomes something like
SELECT FIRST 10
DATE_MODIFIED,
(SELECT FECHA FROM MI_FECHA(DATE_MODIFIED))
FROM INVENTORY
CREATE PROCEDURE MI_FECHA( DATETIME TIMESTAMP )
RETURNS ( FECHA VARCHAR( 60 ) )
AS
DECLARE VARIABLE MES VARCHAR (60) =
'-ENE--FEB--MAR--ABR--MAY--JUN--JUL--AGO--SEP--OCT--NOV--DIC-';
DECLARE VARIABLE DAYS_STR VARCHAR(4);
DECLARE VARIABLE HOURS_STR VARCHAR(4);
DECLARE VARIABLE MINS_STR VARCHAR(4);
DECLARE VARIABLE AM_PM_STR VARCHAR(4);
BEGIN
IF (COALESCE(DATETIME,NULL) = NULL) THEN
FECHA = 'Fetcha Invalido';
ELSE
BEGIN
DAYS_STR = EXTRACT (DAY FROM DATETIME);
IF (DAYS_STR < 10) THEN
DAYS_STR = '0' || DAYS_STR;
FECHA = DAYS_STR;
FECHA = FECHA || SUBSTRING(MES FROM (EXTRACT (MONTH FROM DATETIME)-1)*5+1
FOR 5);
FECHA = FECHA || CAST(EXTRACT (YEAR FROM DATETIME) AS CHAR(4)) || ' ';
HOURS_STR = EXTRACT (HOUR FROM DATETIME);
IF (HOURS_STR < 12) THEN
AM_PM_STR = ' am';
ELSE
BEGIN
HOURS_STR = CAST(HOURS_STR AS INTEGER) - 12;
AM_PM_STR = ' pm';
END
IF (HOURS_STR < 10) THEN
HOURS_STR = '0' || HOURS_STR;
MINS_STR = EXTRACT (MINUTE FROM DATETIME);
IF (MINS_STR < 10) THEN
MINS_STR = '0' || MINS_STR;
FECHA = FECHA || HOURS_STR || ':' || MINS_STR || AM_PM_STR;
END
SUSPEND;
END
and then the select simply becomes something like
SELECT FIRST 10
DATE_MODIFIED,
(SELECT FECHA FROM MI_FECHA(DATE_MODIFIED))
FROM INVENTORY
----- Original Message -----
From: "Nando" <duque.hernando@...>
To: <firebird-support@yahoogroups.com>
Sent: Saturday, November 28, 2009 5:51 AM
Subject: [firebird-support] Re: How to pass a TIMESTAMP value to a Pascal
UDF
> Hi
>
>> you can do a lot with the existing built in functions, like
>> select first 1 substring(date_modified from 1 for 16) from inventory
>
> Yes you are rigth but, I get strings like this: "24-JAN-2007 18:20:00.00".
> How can I translate in into "24-ENE-2007 6:20 pm" ?
>
> Thank you
>
> Nando.
>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>