Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Firebird e Interbase (https://www.clubdelphi.com/foros/forumdisplay.php?f=19)
-   -   consulta con hora y fecha (https://www.clubdelphi.com/foros/showthread.php?t=87765)

FGarcia 22-02-2015 19:52:40

consulta con hora y fecha
 
Hola!

Tengo este código:

Código SQL [-]
SELECT 
COUNT(*) AS HCuenta
FROM Datos 
WHERE horafecha BETWEEN ('16/02/2015 6:00:00 a.m.') AND ('16/02/2015 1:59:59 p.m.')

al tratar de ejecutarla me envía el mensaje:

---------------------------
Error
---------------------------

conversion error from string "16/02/2015 1:59:59 p.m.".
---------------------------
OK
---------------------------

Ya probé diversas combinaciones y no logro ejecutarla. ¿Alguien podría orientarme en el error?

Agradezco su tiempo.

Casimiro Notevi 22-02-2015 20:58:32

Nunca usé lo de a.m. y p.m. y creo que no sirve.
Cámbialo por el sistema de 24 horas.
Código SQL [-]
'16.02.2015 06:00:00' and '16.02.2015 13:59:59'

FGarcia 22-02-2015 23:44:27

Gracias Casi!

Efectivamente así funciono. Esta es una prueba que estoy haciendo, en el programa final esto lo ejecuto enviando una cadena como parámetro con el formato que tenia en el ejemplo y así funciona bien, creo que Firebird hace alguna conversión para esa cadena y por eso no me funcionaba en forma directa.

Saludos!!

Casimiro Notevi 22-02-2015 23:49:36

Cita:

How to set the Firebird date format or why doesn't dd/mm/yyyy work?


In general, you shouldn't ever be using the strings user entered directly in your queries. Convert the string into some kind of Date object and pass it to Firebird as query parameter.

If you still wish to use strings, here are the formats that Firebird supports:

DD.MM.YYYY
MM/DD/YYYY
YYYY-MM-DD

In all of them, year can be written with 2 or 4 digits. The same format is also used in timestamps.

Additionally, you can use the format where months are represented by 3-character name (JAN,FEB,MAR...) instead of number (01,02,03...):

DD-MMM-YYYY
http://www.firebirdfaq.org/faq137/


La franja horaria es GMT +2. Ahora son las 08:11:48.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi