4
There is a native Firebird function that formats the date(date)?
Just as in Mysql we have the DATE_FORMAT() function would have something similar in Firebird?
4
There is a native Firebird function that formats the date(date)?
Just as in Mysql we have the DATE_FORMAT() function would have something similar in Firebird?
4
Firebird does not have a date-ready function. I believe you can create a precedent that returns a formatted date.Follow a SELECT to return the date in the dd/MM/yyyy format.
SELECT CAST(EXTRACT(DAY FROM Campo) || '/' || EXTRACT(MONTH FROM
Campo) || '/' || EXTRACT(YEAR FROM Campo) AS VARCHAR) AS DIA_MES_ANO FROM Tabela;
Procedure that passes an integer value that returns the date according to a country, in this case Brazil equal to 1 and USA equal to 2 for the variable res declared as return.
create procedure formatdate(locale int) returns (res date)
begin
// Formato brasileiro
IF (locale = 1) THEN BEGIN
SELECT CAST(EXTRACT(DAY FROM Campo) || '/' || EXTRACT(MONTH FROM
Campo) || '/' || EXTRACT(YEAR FROM Campo) AS VARCHAR) AS DIA_MES_ANO FROM Tabela INTO res;
END;
// Formato americano
IF (locale = 2) THEN BEGIN
SELECT CAST(EXTRACT(MONTH FROM Campo) || '/' || EXTRACT(DAY FROM
Campo) || '/' || EXTRACT(YEAR FROM Campo) AS VARCHAR) AS DIA_MES_ANO FROM Tabela INTO res;
END;
end;
0
I use a proc for that.
create or alter procedure SP_FORMATA_DATA (
DATA DATA)
returns (
RESULTADO varchar(10))
as
BEGIN
-- Sem data?
IF(DATA IS NULL)THEN
-- Sem resultado tambem.
RESULTADO = NULL;
ELSE
-- Converte a data p/ texto no formato brasileiro.
RESULTADO = (LPAD(EXTRACT(DAY FROM DATA), 2, '0') || '/' ||
LPAD(EXTRACT(MONTH FROM DATA), 2, '0') || '/' ||
LPAD(EXTRACT(YEAR FROM DATA), 4, '0'));
-- Retorna o resultado.
SUSPEND;
END
And to call the proc:
SELECT * FROM SP_FORMATA_DATA('2014.04.14')
0
Here I use Visual Studio 2015 and use it in the query routines by dates
Where ( SUBSTRING( DST001.DATA_FAT FROM 7 FOR 4 )||SUBSTRING( DST001.DATA_FAT FROM 4 FOR 2 )||SUBSTRING( DST001.DATA_FAT FROM 1 FOR 2 )) BETWEEN '" & ANOMESDIA_INI & "' And '" & ANOMSDIA_FIM & "'" &
try like this In my DB I store the dates as varchar(10) - DD/MM/YYYY I take the dates of a datetimepicker and assemble the anomesdia strings. ANOMESDIA_INI as string = "20170919" ANOMESDIA_FIM as string = "20170922"
Browser other questions tagged firebird
You are not signed in. Login or sign up in order to post.