Jump to content
Fórum Script Brasil
  • 0

pesquisa entre datas


lodredica

Question

COlegas, tenho duas tabelas

agendatemporaria

id_agenda_temporaria` int(11) NOT NULL AUTO_INCREMENT,

`id_cligeral` int(5) NOT NULL,

`evento` varchar(200) NOT NULL,

`dtevento` date NOT NULL,

`autor` varchar(200) NOT NULL,

`data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

`hora` varchar(5) NOT NULL,

`conteudo` text NOT NULL,

`local` varchar(200) NOT NULL,

PRIMARY KEY (`id_agenda_temporaria`)

)

cligeral

cligeral` (

`id_cligeral` int(100) NOT NULL AUTO_INCREMENT,

`nome` varchar(255) DEFAULT NULL,

`rua` varchar(255) DEFAULT NULL,

`num` varchar(255) DEFAULT NULL,

`bairro` varchar(255) DEFAULT NULL,

`cidade` varchar(255) DEFAULT NULL,

`uf` varchar(255) DEFAULT NULL,

`email` varchar(255) DEFAULT NULL,

`data_nasc` datetime DEFAULT NULL,

`cpf` varchar(255) DEFAULT NULL,

`rg` varchar(255) DEFAULT NULL,

`cep` varchar(255) DEFAULT NULL,

`data_cadastro` timestamp NOT NULL DEFAULT

Preciso resgatar a data dos eventos cadastrados nesta agenda. O script que uso resgata dados com identificadores iguais, mas quando peço para filtrar as datas ele retorna nada.

SELECT *

FROM cligeral AS c INNER JOIN agendatemporaria AS a ON a.id_cligeral=c.id_cligeral

WHERE date_format( dtevento, 'd/m/Y' ) BETWEEN datainicio AND datafim

ORDER BY a.dtevento

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
...

SELECT *

FROM cligeral AS c INNER JOIN agendatemporaria AS a ON a.id_cligeral=c.id_cligeral

WHERE date_format( dtevento, 'd/m/Y' ) BETWEEN datainicio AND datafim

ORDER BY a.dtevento

O SELECT acima está errado. Você deve converter datainicio e datafim para o formato data e não dtevento para caracter.

Datainicio e datafim devem estar no formato %Y-%m-%d. Ou seja AAAA-MM-DD

Link to comment
Share on other sites

  • 0

Ok, sendo assim, pelo que entendi tenho que fazer

SELECT *

FROM cligeral AS c INNER JOIN agendatemporaria AS a ON a.id_cligeral=c.id_cligeral

WHERE date_format dtevento BETWEEN date_format (%Y-%m-%d)datainicio AND date_format (%Y-%m-%d)datafim

ORDER BY a.dtevento

Em casa vou testar.

valeu

Link to comment
Share on other sites

  • 0

Ola

Alterei o meu BD e minha SQL ficou assim

SELECT * FROM cliente

AS c INNER JOIN agenda AS a

ON

c.id=a.id_cliente

WHERE dtevento BETWEEN inicio AND fim ORDER BY a.dtevento

Mas a consulta é vazia, mesmo com o BD tendo eventos para o dia selecionado

Aparentemente o problema é mesmo com a data pois quando consulto da seguinte forma, os dados vem corretamente

SELECT * FROM cliente

AS c INNER JOIN agenda AS a

ON

c.id=a.id_cliente

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...